Skip to content

Commit

Permalink
refactor: code splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jan 1, 2022
1 parent 1d82441 commit fa83e8f
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 113 deletions.
8 changes: 8 additions & 0 deletions packages/@yarn-tool/fix-all/lib/root/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/@yarn-tool/fix-all/lib/root/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { npmHostedGitInfoLazy } from '@yarn-tool/pkg-git-info';
import { PackageJsonLoader } from 'npm-package-json-loader';
import { WorkspacesScope } from '@yarn-tool/ws-scope';
import { sortPackageJson } from 'sort-package-json3';
import { defaultWorkspaceRootScripts } from '@yarn-tool/pkg-entry-util/lib/preset/ws-root-scripts';
import { fillDummyScripts } from '@yarn-tool/pkg-entry-util/lib/preset/dummy';

export function _fixRoot(options: Required<IFillPkgHostedInfoOptions>)
{
Expand Down Expand Up @@ -54,6 +56,13 @@ export function _fixWsRoot(options: ITSRequiredPick<IFillPkgHostedInfoOptions, '
targetDir: options.rootData.ws,
});

Object.entries(fillDummyScripts(defaultWorkspaceRootScripts())).forEach(([key, value]) =>
{
runtime.root_pkg_json.data.scripts[key] ??= value;
});

runtime.root_pkg_json.write();

let wss = new WorkspacesScope(runtime.rootData.ws);
wss.syncValue();
wss.save();
Expand Down
1 change: 1 addition & 0 deletions packages/@yarn-tool/pkg-entry-util/lib/preset/dummy.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function fillDummyScripts<T extends Record<string, string>>(scripts?: T, prefix?: string): T;
29 changes: 29 additions & 0 deletions packages/@yarn-tool/pkg-entry-util/lib/preset/dummy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions packages/@yarn-tool/pkg-entry-util/lib/preset/dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export function fillDummyScripts<T extends Record<string, string>>(scripts?: T, prefix?: string)
{
// @ts-ignore
scripts ??= {};

let text = `echo ${prefix ?? ''}`.trim();

([
'preversion',
'version',
'prepublishOnly',
'postversion',
'publish',
'prepublish',
'postpublish',
'postpublishOnly',
'prepare',
'prepack',
'pack',
'postpack',
] as const).forEach(k =>
{
// @ts-ignore
scripts[k] ??= `${text} ${k}`
});
return scripts;
}
27 changes: 27 additions & 0 deletions packages/@yarn-tool/pkg-entry-util/lib/preset/ws-root-scripts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export declare function defaultWorkspaceRootScripts(): {
"test:all": string;
"build:all": string;
"review:all": string;
"coverage:all": string;
"lint:all": string;
preversion: string;
"lerna:publish": string;
"lerna:publish:yes": string;
"prepublishOnly:root": string;
"prepublishOnly:lockfile": string;
"prepublishOnly:check-bin": string;
"prepare:fix-ws-links": string;
"prepublishOnly:update": string;
ncu: string;
"ncu:root": string;
"ncu:ws": string;
"sort-package-json": string;
"sort-package-json:root": string;
"sort-package-json:ws": string;
postpublishOnly: string;
"postpublishOnly:ws-root-changelog": string;
test: string;
"install:reset-lockfile": string;
"ws:fix-all": string;
"tsc:showConfig": string;
};
34 changes: 34 additions & 0 deletions packages/@yarn-tool/pkg-entry-util/lib/preset/ws-root-scripts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions packages/@yarn-tool/pkg-entry-util/lib/preset/ws-root-scripts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export function defaultWorkspaceRootScripts()
{
return {
"test:all": "lerna run test --concurrency 1",
"build:all": "lerna run build --concurrency 1",
"review:all": "lerna run review --concurrency 1",
"coverage:all": "lerna run coverage --concurrency 1",
"lint:all": "lerna run lint --concurrency 1",
"preversion": "yt ws run test",
"lerna:publish": "yarn run prepublishOnly:root && lerna publish && yarn run postpublishOnly",
"lerna:publish:yes": "yarn run prepublishOnly:root && lerna publish --yes --bump patch && yarn run postpublishOnly",
"prepublishOnly:root": "yarn run prepublishOnly:check-bin && yarn run prepare:fix-ws-links",
"prepublishOnly:lockfile": "ynpx --quiet sync-lockfile",
"prepublishOnly:check-bin": "ynpx --quiet @yarn-tool/check-pkg-bin",
"prepare:fix-ws-links": "ynpx --quiet @yarn-tool/fix-ws-links",
"prepublishOnly:update": "yarn run ncu && yarn run sort-package-json",
"ncu": "yarn run ncu:root && yarn run ncu:ws",
"ncu:root": "yarn-tool ncu -u",
"ncu:ws": "yarn-tool ws exec yarn-tool ncu -- -u",
"sort-package-json": "yarn run sort-package-json:root && yarn run sort-package-json:ws",
"sort-package-json:root": "yarn-tool sort",
"sort-package-json:ws": "yarn-tool ws sort",
"postpublishOnly": "yarn run postpublishOnly:ws-root-changelog & echo postpublishOnly",
"postpublishOnly:ws-root-changelog": "ynpx ws-root-changelog & git add ./CHANGELOG.md & git commit ./CHANGELOG.md -m \"chore(changelog): update changelog toc in workspaces root\" & echo update changelog toc in workspaces root",
"test": "yarn-tool ws run test",
"install:reset-lockfile": "yarn-tool install --reset-lockfile",
"ws:fix-all":"yarn-tool fix-all --overwriteHostedGitInfo",
"tsc:showConfig": "ynpx get-current-tsconfig -p",
}
}
44 changes: 4 additions & 40 deletions packages/create-yarn-workspaces/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 4 additions & 39 deletions packages/create-yarn-workspaces/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { IPackageJson } from '@ts-type/package-dts/package-json';
import { defaultWorkspaceRootScripts } from '@yarn-tool/pkg-entry-util/lib/preset/ws-root-scripts';
import { fillDummyScripts } from '@yarn-tool/pkg-entry-util/lib/preset/dummy';

export function getDefaultPackageJson(name?: string): IPackageJson
{
Expand All @@ -13,32 +15,7 @@ export function getDefaultPackageJson(name?: string): IPackageJson
keywords: [
"create-by-yarn-tool",
],
"scripts": {
"test:all": "lerna run test --concurrency 1",
"build:all": "lerna run build --concurrency 1",
"review:all": "lerna run review --concurrency 1",
"coverage:all": "lerna run coverage --concurrency 1",
"lint:all": "lerna run lint --concurrency 1",
"preversion": "yt ws run test",
"lerna:publish": "yarn run prepublishOnly:root && lerna publish && yarn run postpublishOnly",
"lerna:publish:yes": "yarn run prepublishOnly:root && lerna publish --yes --bump patch && yarn run postpublishOnly",
"prepublishOnly:root": "yarn run prepublishOnly:check-bin && yarn run prepare:fix-ws-links",
"prepublishOnly:lockfile": "ynpx --quiet sync-lockfile",
"prepublishOnly:check-bin": "ynpx --quiet @yarn-tool/check-pkg-bin",
"prepare:fix-ws-links": "ynpx --quiet @yarn-tool/fix-ws-links",
"prepublishOnly:update": "yarn run ncu && yarn run sort-package-json",
"ncu": "yarn run ncu:root && yarn run ncu:ws",
"ncu:root": "yarn-tool ncu -u",
"ncu:ws": "yarn-tool ws exec yarn-tool ncu -- -u",
"sort-package-json": "yarn run sort-package-json:root && yarn run sort-package-json:ws",
"sort-package-json:root": "yarn-tool sort",
"sort-package-json:ws": "yarn-tool ws sort",
"postpublishOnly": "yarn run postpublishOnly:ws-root-changelog & echo postpublishOnly",
"postpublishOnly:ws-root-changelog": "ynpx ws-root-changelog & git add ./CHANGELOG.md & git commit ./CHANGELOG.md -m \"chore(changelog): update changelog toc in workspaces root\" & echo update changelog toc in workspaces root",
"test": "yarn-tool ws run test",
"install:reset-lockfile": "yarn-tool install --reset-lockfile",
"tsc:showConfig": "ynpx get-current-tsconfig -p",
},
"scripts": defaultWorkspaceRootScripts(),
"dependencies": {
"ts-type": "^1.2.32",
"tslib": "^2.3.0",
Expand All @@ -61,19 +38,7 @@ export function getDefaultPackageJson(name?: string): IPackageJson
"resolutions": {},
} as any;

[
'preversion',
'version',
'prepublishOnly',
'postversion',
'publish',
'prepublish',
'postpublish',
'postpublishOnly',
].forEach(k =>
{
json.scripts[k] ??= `echo workspaces ${k}`
});
fillDummyScripts(json.scripts, 'workspaces');

return json;
}
Expand Down
1 change: 1 addition & 0 deletions packages/create-yarn-workspaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"dependencies": {
"@ts-type/package-dts": "^1.0.56",
"@yarn-tool/find-root": "^1.0.60",
"@yarn-tool/pkg-entry-util": "^1.0.3",
"@yarn-tool/static-file": "^1.0.87",
"debug-color2": "^1.2.7",
"find-yarn-workspace-root2": "^1.2.36",
Expand Down
19 changes: 2 additions & 17 deletions packages/npm-init2/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa83e8f

Please sign in to comment.