chore: Merge remote-tracking branch 'origin/main' into fd-fix-client-components-import
This commit is contained in:
commit
2adc9767cb
|
@ -1,11 +1,13 @@
|
|||
![Hydrogen logo](/docs/images/HydrogenLogo.png)
|
||||
|
||||
📚 [Docs](https://shopify.dev/custom-storefronts/hydrogen) | 🗣 [Discord](https://discord.gg/Hefq6w5c5d) | 💬 [Discussions](https://github.com/Shopify/hydrogen/discussions) | 📝 [Changelog](./packages/hydrogen/CHANGELOG.md)
|
||||
📚 [Docs](https://shopify.dev/custom-storefronts/hydrogen) | 🗣 [Discord](https://discord.gg/Hefq6w5c5d) | 💬 [Discussions](https://github.com/Shopify/hydrogen/discussions) | 📝 [Changelog](./packages/hydrogen/CHANGELOG.md)
|
||||
|
||||
Hydrogen is a **React-based framework** for building dynamic, **Shopify-powered** custom storefronts.
|
||||
|
||||
Spin up a Hydrogen app in your browser with our [playground](https://hydrogen.new/) or set up your local environment with the instructions below ⬇️
|
||||
|
||||
**This is a developer preview of Hydrogen**. The documentation will be updated as Shopify [introduces new features and refines existing functionality](https://github.com/Shopify/hydrogen/releases). Production launches of Hydrogen custom storefronts aren't yet supported as Shopify is evolving the Hydrogen framework.
|
||||
|
||||
## Getting Started
|
||||
|
||||
**Requirements:**
|
||||
|
@ -63,4 +65,3 @@ Learn more about [getting started with Hydrogen](https://shopify.dev/custom-stor
|
|||
- [`@shopify/hydrogen-plugin-sanity`](https://www.npmjs.com/package/@shopify/hydrogen-plugin-sanity)
|
||||
- [`create-hydrogen-app`](https://www.npmjs.com/package/create-hydrogen-app)
|
||||
- [`eslint-plugin-hydrogen`](https://www.npmjs.com/package/eslint-plugin-hydrogen)
|
||||
- [`@shopify/create-hydrogen` (deprecated)](https://www.npmjs.com/package/@shopify/create-hydrogen)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"command": {}
|
||||
|
|
|
@ -65,7 +65,8 @@
|
|||
"ts-node": "^10.2.1",
|
||||
"typescript": "^4.2.3",
|
||||
"vite": "^2.6.0",
|
||||
"yorkie": "^2.0.0"
|
||||
"yorkie": "^2.0.0",
|
||||
"glob": "^7.2.0"
|
||||
},
|
||||
"gitHooks": {
|
||||
"pre-commit": "lint-staged",
|
||||
|
|
|
@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
<!-- ## Unreleased -->
|
||||
## Unreleased
|
||||
|
||||
- Add ability to explicitly set the root for the running command using the `--root` flag
|
||||
|
||||
## 0.6.0 - 2021-11-05
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ export enum Template {
|
|||
* Create a new `@shopify/hydrogen` app.
|
||||
*/
|
||||
export async function init(env: Env) {
|
||||
const {ui, fs, workspace} = env;
|
||||
const {ui, fs, workspace, ...passThroughEnv} = env;
|
||||
|
||||
const name = await ui.ask('What do you want to name this app?', {
|
||||
validate: validateProjectName,
|
||||
|
@ -43,8 +43,8 @@ export async function init(env: Env) {
|
|||
);
|
||||
|
||||
if (template === Template.None) {
|
||||
const context = {name};
|
||||
await app({ui, fs, workspace, context});
|
||||
const context = {name, ...passThroughEnv.context};
|
||||
await app({...passThroughEnv, ui, fs, workspace, context});
|
||||
}
|
||||
|
||||
if (template === Template.Default) {
|
||||
|
|
|
@ -4,9 +4,14 @@ import {Cli} from './ui';
|
|||
import {Workspace} from './workspace';
|
||||
import {Fs} from './fs';
|
||||
import {loadConfig} from './config';
|
||||
import {Env} from './types';
|
||||
|
||||
const logger = debug('hydrogen');
|
||||
|
||||
interface ModuleType {
|
||||
default: (env: Env) => Promise<void>;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const rawInputs = process.argv.slice(2);
|
||||
const {command, root} = parseCliArguments(rawInputs);
|
||||
|
@ -22,10 +27,23 @@ const logger = debug('hydrogen');
|
|||
throw new InputError();
|
||||
}
|
||||
|
||||
async function runModule(module: ModuleType) {
|
||||
logger('Run start');
|
||||
|
||||
await module.default({
|
||||
ui,
|
||||
fs,
|
||||
workspace,
|
||||
logger: debug(`hydrogen/${command}`),
|
||||
});
|
||||
|
||||
logger('Run end');
|
||||
}
|
||||
|
||||
try {
|
||||
const module = await import(`./commands/${command}`);
|
||||
|
||||
await module.default({ui, fs, workspace});
|
||||
await runModule(module);
|
||||
} catch (error) {
|
||||
logger(error);
|
||||
|
||||
|
@ -36,7 +54,9 @@ const logger = debug('hydrogen');
|
|||
ui.printFile(file);
|
||||
}
|
||||
|
||||
await workspace.commit();
|
||||
if (command === 'init') {
|
||||
await workspace.commit();
|
||||
}
|
||||
})().catch((error) => {
|
||||
logger(error);
|
||||
process.exitCode = 1;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import debug from 'debug';
|
||||
import {Workspace} from './workspace';
|
||||
import {Ui} from './ui';
|
||||
import {Fs} from './fs';
|
||||
|
@ -9,6 +10,7 @@ export interface Env<Context = {}> {
|
|||
workspace: Workspace;
|
||||
fs: Fs;
|
||||
context?: Context;
|
||||
logger: debug.Debugger;
|
||||
}
|
||||
|
||||
export enum ComponentType {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {join, resolve} from 'path';
|
||||
import {resolve} from 'path';
|
||||
|
||||
import minimist from 'minimist';
|
||||
|
||||
|
@ -15,10 +15,8 @@ const DEFAULT_SUBCOMMANDS = {
|
|||
export function parseCliArguments(rawInputs?: string[]) {
|
||||
const inputs = minimist(rawInputs || []);
|
||||
const command = inputs._[0];
|
||||
const root =
|
||||
command === 'create' && inputs._[2]
|
||||
? join(process.cwd(), inputs._[2])
|
||||
: process.cwd();
|
||||
|
||||
const root = inputs.root || process.cwd();
|
||||
const subcommand =
|
||||
inputs._[1] || DEFAULT_SUBCOMMANDS[command as 'create' | 'version'];
|
||||
const {debug} = inputs;
|
||||
|
|
|
@ -7,6 +7,11 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|||
|
||||
<!-- ## Unreleased -->
|
||||
|
||||
## 0.6.1 - 2021-11-08
|
||||
|
||||
- Wrap LocalizationProvider in a proper Suspense boundary
|
||||
- Optimize `@headlessui/react` to prevent dev server slowness while we investigate a long term solution
|
||||
|
||||
## 0.6.0 - 2021-11-05
|
||||
|
||||
- No updates. Transitive dependency bump.
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"access": "public",
|
||||
"@shopify:registry": "https://registry.npmjs.org"
|
||||
},
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "dev",
|
||||
"description": "This is a dev environment for Hydrogen",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
@ -32,7 +32,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@headlessui/react": "^1.4.1",
|
||||
"@shopify/hydrogen": "^0.6.0",
|
||||
"@shopify/hydrogen": "^0.6.1",
|
||||
"compression": "^1.7.4",
|
||||
"express": "^4.17.1",
|
||||
"graphql-tag": "^2.12.4",
|
||||
|
|
|
@ -17,10 +17,10 @@ export default function App({...serverState}) {
|
|||
const pages = import.meta.globEager('./pages/**/*.server.[jt]sx');
|
||||
|
||||
return (
|
||||
<ShopifyServerProvider shopifyConfig={shopifyConfig} {...serverState}>
|
||||
<LocalizationProvider>
|
||||
<CartProvider>
|
||||
<Suspense fallback={<LoadingFallback />}>
|
||||
<Suspense fallback={<LoadingFallback />}>
|
||||
<ShopifyServerProvider shopifyConfig={shopifyConfig} {...serverState}>
|
||||
<LocalizationProvider>
|
||||
<CartProvider>
|
||||
<DefaultSeo />
|
||||
<Switch>
|
||||
<DefaultRoutes
|
||||
|
@ -29,9 +29,9 @@ export default function App({...serverState}) {
|
|||
fallback={<NotFound />}
|
||||
/>
|
||||
</Switch>
|
||||
</Suspense>
|
||||
</CartProvider>
|
||||
</LocalizationProvider>
|
||||
</ShopifyServerProvider>
|
||||
</CartProvider>
|
||||
</LocalizationProvider>
|
||||
</ShopifyServerProvider>
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
<!-- ## Unreleased -->
|
||||
## Unreleased
|
||||
|
||||
- Added new `hydrogen/typescript` config
|
||||
- Added `env#node: true` and `parserOptions#sourceType: 'module'` to core config
|
||||
- Fixed issue requiring typescript to be install on non-typescript projects
|
||||
|
||||
## 0.6.0 - 2021-11-05
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
"ts-jest": "^26.5.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": ">= 4",
|
||||
"eslint": ">=5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
import rules from './rules';
|
||||
|
||||
export default {
|
||||
plugins: ['hydrogen'],
|
||||
extends: [
|
||||
'plugin:@shopify/typescript',
|
||||
'plugin:@shopify/react',
|
||||
'plugin:@shopify/node',
|
||||
'plugin:@shopify/prettier',
|
||||
],
|
||||
rules,
|
||||
};
|
|
@ -1,12 +0,0 @@
|
|||
import rules from './rules';
|
||||
|
||||
export default {
|
||||
plugins: ['hydrogen'],
|
||||
extends: [
|
||||
'plugin:@shopify/esnext',
|
||||
'plugin:@shopify/react',
|
||||
'plugin:@shopify/node',
|
||||
'plugin:@shopify/prettier',
|
||||
],
|
||||
rules,
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
export default {
|
||||
'hydrogen/no-state-in-server-components': 'error',
|
||||
'hydrogen/prefer-image-component': 'error',
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
import {deepMerge} from '@typescript-eslint/experimental-utils/dist/eslint-utils';
|
||||
import overrides from './overrides';
|
||||
import hydrogen from './hydrogen';
|
||||
|
||||
export default deepMerge(hydrogen, overrides);
|
|
@ -1,45 +0,0 @@
|
|||
export default {
|
||||
// TODO: We may want to change the configuration for the following 3 rules
|
||||
'jsx-a11y/click-events-have-key-events': 'off',
|
||||
'jsx-a11y/no-noninteractive-element-interactions': 'off',
|
||||
'react/jsx-filename-extension': ['error', {extensions: ['.tsx', '.jsx']}],
|
||||
|
||||
/**
|
||||
* Rules below this line are intentionally disabled for different reasons
|
||||
*/
|
||||
|
||||
// The following 2 rules are very strict and disabled here to lessen developer frustration
|
||||
'@shopify/jsx-no-hardcoded-content': 'off',
|
||||
'@shopify/jsx-no-complex-expressions': 'off',
|
||||
|
||||
/**
|
||||
* eslint overrides
|
||||
*/
|
||||
|
||||
// We often define GraphQL queries at the bottom of the file which would be a violation for this rule
|
||||
'no-use-before-define': 'off',
|
||||
// We agree that warning comments acceptable
|
||||
'no-warning-comments': 'off',
|
||||
|
||||
/**
|
||||
* react overrides
|
||||
*/
|
||||
|
||||
// Following Next.js and likely this will be the default in most frameworks
|
||||
'react/react-in-jsx-scope': 'off',
|
||||
// We default to typescript for typing, non typescript projects can override this rule if they want
|
||||
'react/prop-types': 'off',
|
||||
|
||||
/**
|
||||
* import overrides
|
||||
*/
|
||||
|
||||
// TODO: We should turn these on, at least partially
|
||||
// 'import/no-unresolved': ['off'],
|
||||
// 'import/extensions': ['off'],
|
||||
|
||||
// These two rules result in a significant number of false positives so we
|
||||
// need to keep them disabled.
|
||||
'jsx-a11y/label-has-for': 'off',
|
||||
'jsx-a11y/control-has-associated-label': 'off',
|
||||
};
|
|
@ -11,6 +11,7 @@ export default {
|
|||
env: {
|
||||
es2021: true,
|
||||
browser: true,
|
||||
node: true,
|
||||
},
|
||||
settings: {
|
||||
react: {
|
||||
|
@ -21,6 +22,7 @@ export default {
|
|||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
'no-console': 'warn',
|
||||
|
@ -39,54 +41,6 @@ export default {
|
|||
},
|
||||
ignorePatterns: ['node_modules/', 'build/', '*.graphql.d.ts', '*.graphql.ts'],
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
extends: ['plugin:@typescript-eslint/recommended'],
|
||||
rules: {
|
||||
'react/prop-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-empty-interface': 'off',
|
||||
'@typescript-eslint/ban-types': [
|
||||
'error',
|
||||
{
|
||||
types: {
|
||||
String: {message: 'Use string instead', fixWith: 'string'},
|
||||
Boolean: {message: 'Use boolean instead', fixWith: 'boolean'},
|
||||
Number: {message: 'Use number instead', fixWith: 'number'},
|
||||
Object: {message: 'Use object instead', fixWith: 'object'},
|
||||
Array: {message: 'Provide a more specific type'},
|
||||
ReadonlyArray: {message: 'Provide a more specific type'},
|
||||
},
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/naming-convention': [
|
||||
'error',
|
||||
{
|
||||
selector: 'default',
|
||||
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
|
||||
leadingUnderscore: 'allowSingleOrDouble',
|
||||
trailingUnderscore: 'allowSingleOrDouble',
|
||||
},
|
||||
{
|
||||
selector: 'typeLike',
|
||||
format: ['PascalCase'],
|
||||
},
|
||||
{
|
||||
selector: 'typeParameter',
|
||||
format: ['PascalCase'],
|
||||
leadingUnderscore: 'allow',
|
||||
},
|
||||
{
|
||||
selector: 'interface',
|
||||
format: ['PascalCase'],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['*.test.*'],
|
||||
plugins: ['jest'],
|
||||
|
|
52
packages/eslint-plugin/src/configs/typescript.ts
Normal file
52
packages/eslint-plugin/src/configs/typescript.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
export default {
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts', '*.tsx'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
extends: ['plugin:@typescript-eslint/recommended'],
|
||||
rules: {
|
||||
'react/prop-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-empty-interface': 'off',
|
||||
'@typescript-eslint/ban-types': [
|
||||
'error',
|
||||
{
|
||||
types: {
|
||||
String: {message: 'Use string instead', fixWith: 'string'},
|
||||
Boolean: {message: 'Use boolean instead', fixWith: 'boolean'},
|
||||
Number: {message: 'Use number instead', fixWith: 'number'},
|
||||
Object: {message: 'Use object instead', fixWith: 'object'},
|
||||
Array: {message: 'Provide a more specific type'},
|
||||
ReadonlyArray: {message: 'Provide a more specific type'},
|
||||
},
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/naming-convention': [
|
||||
'error',
|
||||
{
|
||||
selector: 'default',
|
||||
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
|
||||
leadingUnderscore: 'allowSingleOrDouble',
|
||||
trailingUnderscore: 'allowSingleOrDouble',
|
||||
},
|
||||
{
|
||||
selector: 'typeLike',
|
||||
format: ['PascalCase'],
|
||||
},
|
||||
{
|
||||
selector: 'typeParameter',
|
||||
format: ['PascalCase'],
|
||||
leadingUnderscore: 'allow',
|
||||
},
|
||||
{
|
||||
selector: 'interface',
|
||||
format: ['PascalCase'],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
|
@ -1,9 +1,11 @@
|
|||
import recommended from './configs/recommended';
|
||||
import hydrogen from './configs/hydrogen';
|
||||
import typescript from './configs/typescript';
|
||||
|
||||
export {rules} from './rules';
|
||||
|
||||
export const configs = {
|
||||
recommended,
|
||||
hydrogen,
|
||||
typescript,
|
||||
};
|
||||
|
|
|
@ -142,10 +142,11 @@ export class DocsGen {
|
|||
|
||||
await componentResult.docs(componentEntryBase);
|
||||
|
||||
await Promise.all([
|
||||
componentResult.writeReadme(componentEntryBase),
|
||||
componentResult.writeDevDoc(componentPaths.output),
|
||||
]);
|
||||
await componentResult.writeReadme(componentEntryBase);
|
||||
|
||||
if (this.writeDocs) {
|
||||
componentResult.writeDevDoc(componentPaths.output);
|
||||
}
|
||||
|
||||
listItems.push({
|
||||
name: `<a href="${componentUrl}">${name}</a>`,
|
||||
|
|
|
@ -25,7 +25,7 @@ export class FileResult {
|
|||
public async writeDevDoc(path: string) {
|
||||
const result = inPageAnchors(this.staged.join(''));
|
||||
|
||||
const comment = `<!-- This file is generated from the source code and any changes you make here will be overwritten. -->`;
|
||||
const comment = `<!-- This file is generated from source code in the Shopify/hydrogen repo. Any changes you make here will be overwritten. -->`;
|
||||
|
||||
await this.write(path, [this.frontMatter, comment, result].join('\n\n'));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ export class FileResult {
|
|||
|
||||
const localPath = path.replace(resolve('.'), '');
|
||||
const finalPath = resolve(path, 'README.md');
|
||||
const comment = `<!-- This file is generated from the source code. Edit the files in ${localPath} and run 'yarn generate-docs' at the root of this repo. -->`;
|
||||
const comment = `<!-- This file is generated from source code in the Shopify/hydrogen repo. Edit the files in ${localPath} and run 'yarn generate-docs' at the root of this repo. -->`;
|
||||
await this.write(
|
||||
finalPath,
|
||||
[comment, ...this.staged].join('\n\n').trim()
|
||||
|
|
|
@ -7,6 +7,10 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|||
|
||||
<!-- ## Unreleased -->
|
||||
|
||||
## 0.6.1 - 2021-11-08
|
||||
|
||||
- No updates. Transitive dependency bump.
|
||||
|
||||
## 0.6.0 - 2021-11-05
|
||||
|
||||
- No updates. Transitive dependency bump.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@shopify/hydrogen-plugin-sanity",
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"description": "Hydrogen plugins for integrating with Sanity",
|
||||
"main": "dist/esnext/index.js",
|
||||
"publishConfig": {
|
||||
|
@ -17,7 +17,7 @@
|
|||
"prepack": "yarn build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@shopify/hydrogen": "^0.6.0"
|
||||
"@shopify/hydrogen": "^0.6.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@shopify/hydrogen": "^0.4.0"
|
||||
|
|
|
@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
<!-- ## Unreleased -->
|
||||
## Unreleased
|
||||
|
||||
- fix: reading property of null for component props
|
||||
|
||||
## 0.6.1 - 2021-11-08
|
||||
|
||||
- No updates. Transitive dependency bump.
|
||||
|
||||
## 0.6.0 - 2021-11-05
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"access": "public",
|
||||
"@shopify:registry": "https://registry.npmjs.org"
|
||||
},
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"description": "Modern custom Shopify storefronts",
|
||||
"license": "MIT",
|
||||
"main": "dist/esnext/index.js",
|
||||
|
|
|
@ -30,6 +30,7 @@ export function renderReactProps(props: any) {
|
|||
function renderReactProp(prop: any): any {
|
||||
if (
|
||||
typeof prop === 'object' &&
|
||||
prop !== null &&
|
||||
prop['$$typeof'] === Symbol.for('react.element')
|
||||
) {
|
||||
if (prop.type instanceof Function) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
export const LIB_VERSION = '0.6.0';
|
||||
export const LIB_VERSION = '0.6.1';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "server-components-worker",
|
||||
"private": true,
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"scripts": {
|
||||
"dev": "DEV=true node start-worker",
|
||||
"build": "yarn build:client && yarn build:worker",
|
||||
|
@ -13,7 +13,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@cloudflare/kv-asset-handler": "*",
|
||||
"@shopify/hydrogen": "^0.6.0",
|
||||
"@shopify/hydrogen": "^0.6.1",
|
||||
"miniflare": "^1.3.3",
|
||||
"react": "18.0.0-alpha-e6be2d531",
|
||||
"react-dom": "18.0.0-alpha-e6be2d531",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "test-server-components",
|
||||
"private": true,
|
||||
"version": "0.6.0",
|
||||
"version": "0.6.1",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "yarn build:client && yarn build:server",
|
||||
|
@ -12,7 +12,7 @@
|
|||
"vite": "^2.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@shopify/hydrogen": "^0.6.0",
|
||||
"@shopify/hydrogen": "^0.6.1",
|
||||
"react": "18.0.0-alpha-e6be2d531",
|
||||
"react-dom": "18.0.0-alpha-e6be2d531",
|
||||
"react-router-dom": "^5.2.0"
|
||||
|
|
154
tests/changelogs.test.ts
Normal file
154
tests/changelogs.test.ts
Normal file
|
@ -0,0 +1,154 @@
|
|||
import {join, resolve} from 'path';
|
||||
|
||||
import {readFileSync} from 'fs-extra';
|
||||
import glob from 'glob';
|
||||
|
||||
const ROOT_PATH = resolve(__dirname, '..');
|
||||
|
||||
const HEADER_START_REGEX = /^## /;
|
||||
const CHANGELOG_INTRO = `# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).`;
|
||||
|
||||
readChangelogs().forEach(({packageChangelogPath, packageChangelog}) => {
|
||||
describe(`changelog consistency for ${packageChangelogPath}`, () => {
|
||||
it('begins with the "Keep a Changelog" intro section', () => {
|
||||
const actualIntro = packageChangelog.substring(0, CHANGELOG_INTRO.length);
|
||||
|
||||
expect(actualIntro).toBe(CHANGELOG_INTRO);
|
||||
});
|
||||
|
||||
it('contains only known headers', () => {
|
||||
const headerLines = packageChangelog
|
||||
.split('\n')
|
||||
.filter((line) => /^\s*#/.exec(line));
|
||||
const offendingHeaders = headerLines.filter(
|
||||
(headerLine) => !headerIsAllowed(headerLine)
|
||||
);
|
||||
|
||||
expect(offendingHeaders).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it('has exactly 1 empty line before headings', () => {
|
||||
const notEnoughSpacingBeforeHeadings = /[^\n]+\n^#.*$/gm;
|
||||
|
||||
expect(packageChangelog).not.toStrictEqual(
|
||||
expect.stringMatching(notEnoughSpacingBeforeHeadings)
|
||||
);
|
||||
});
|
||||
|
||||
it('has exactly 1 empty line after headings', () => {
|
||||
const notEnoughSpacingAfterHeadings = /^#.*$\n[^\n]+/gm;
|
||||
|
||||
expect(packageChangelog).not.toStrictEqual(
|
||||
expect.stringMatching(notEnoughSpacingAfterHeadings)
|
||||
);
|
||||
});
|
||||
|
||||
it('contains an Unreleased header with content, or a commented out Unreleased header with no content', () => {
|
||||
// One of the following must be present
|
||||
// - An Unreleased header, that is immediatly preceded by a level 3 heading ("Changed" etc)
|
||||
// - An Unreleased header, that is immediatly preceded by a bullet ("- ...")
|
||||
// - A commented out Unreleased header, that is immediatly preceded by a level 2 heading (Version info)
|
||||
|
||||
const unreleasedHeaderWithContent = /^## Unreleased\n\n- /gm;
|
||||
const unreleasedHeaderWithSubHeader = /^## Unreleased\n\n### /gm;
|
||||
const commentedUnreleasedHeaderWithNoContent =
|
||||
/^<!-- ## Unreleased -->\n\n## /gm;
|
||||
|
||||
expect([
|
||||
unreleasedHeaderWithContent.test(packageChangelog) ||
|
||||
unreleasedHeaderWithSubHeader.test(packageChangelog),
|
||||
commentedUnreleasedHeaderWithNoContent.test(packageChangelog),
|
||||
]).toContain(true);
|
||||
});
|
||||
|
||||
it('does not contain duplicate headers', () => {
|
||||
const headerLines = packageChangelog
|
||||
.split('\n')
|
||||
.filter(
|
||||
(line) => HEADER_START_REGEX.exec(line) || /## Unreleased/.exec(line)
|
||||
)
|
||||
.sort();
|
||||
const uniqueHeaderLines = headerLines.filter(
|
||||
(element, index, array) => array.indexOf(element) === index
|
||||
);
|
||||
|
||||
expect(headerLines).toStrictEqual(uniqueHeaderLines);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const allowedHeaders = [
|
||||
'# Changelog',
|
||||
'## Unreleased',
|
||||
/^## \d+\.\d+\.\d-\w+\.\d+ - \d\d\d\d-\d\d-\d\d$/, // -alpha.x releases
|
||||
/^## \d+\.\d+\.\d+ - \d\d\d\d-\d\d-\d\d$/,
|
||||
'### Fixed',
|
||||
'### Added',
|
||||
'### Changed',
|
||||
'### Deprecated',
|
||||
'### Removed',
|
||||
'### Security',
|
||||
/^####/,
|
||||
];
|
||||
|
||||
function headerIsAllowed(headerLine) {
|
||||
return allowedHeaders.some((allowedHeader) => {
|
||||
if (allowedHeader instanceof RegExp) {
|
||||
return allowedHeader.test(headerLine);
|
||||
} else {
|
||||
return allowedHeader === headerLine;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function readChangelogs() {
|
||||
const packagesPath = join(ROOT_PATH, 'packages');
|
||||
|
||||
return glob
|
||||
.sync(join(packagesPath, '*/'))
|
||||
.filter(hasPackageJSON)
|
||||
.filter(hasChangelog)
|
||||
.map((packageDir) => {
|
||||
const packageChangelogPath = join(packageDir, 'CHANGELOG.md');
|
||||
const packageChangelog = safeReadSync(packageChangelogPath, {
|
||||
encoding: 'utf8',
|
||||
}).toString('utf-8');
|
||||
|
||||
return {
|
||||
packageDir,
|
||||
packageChangelogPath,
|
||||
packageChangelog,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function safeReadSync(path, options) {
|
||||
try {
|
||||
return readFileSync(path, options);
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function hasChangelog(packageDir) {
|
||||
const changelogJSONPath = join(packageDir, 'CHANGELOG.md');
|
||||
const changelog = safeReadSync(changelogJSONPath, {
|
||||
encoding: 'utf8',
|
||||
});
|
||||
|
||||
return changelog.length > 0;
|
||||
}
|
||||
|
||||
function hasPackageJSON(packageDir) {
|
||||
const packageJSONPath = join(packageDir, 'package.json');
|
||||
const packageJSON = safeReadSync(packageJSONPath, {
|
||||
encoding: 'utf8',
|
||||
});
|
||||
|
||||
return packageJSON.length > 0;
|
||||
}
|
Loading…
Reference in a new issue