piral-cli 1.0.0-pre.2217 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +30 -7
- package/lib/api.js +23 -23
- package/lib/api.js.map +1 -1
- package/lib/apps/add-piral-instance-pilet.d.ts +26 -0
- package/lib/apps/add-piral-instance-pilet.js +53 -0
- package/lib/apps/add-piral-instance-pilet.js.map +1 -0
- package/lib/apps/build-pilet.d.ts +33 -2
- package/lib/apps/build-pilet.js +159 -32
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.d.ts +18 -1
- package/lib/apps/build-piral.js +68 -52
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.d.ts +38 -2
- package/lib/apps/debug-pilet.js +150 -108
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.d.ts +23 -0
- package/lib/apps/debug-piral.js +63 -52
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/declaration-piral.js +5 -3
- package/lib/apps/declaration-piral.js.map +1 -1
- package/lib/apps/index.d.ts +3 -0
- package/lib/apps/index.js +8 -1
- package/lib/apps/index.js.map +1 -1
- package/lib/apps/new-pilet.d.ts +7 -3
- package/lib/apps/new-pilet.js +47 -52
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.d.ts +7 -3
- package/lib/apps/new-piral.js +33 -23
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/pack-pilet.d.ts +9 -0
- package/lib/apps/pack-pilet.js +6 -13
- package/lib/apps/pack-pilet.js.map +1 -1
- package/lib/apps/publish-pilet.d.ts +23 -3
- package/lib/apps/publish-pilet.js +112 -62
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.d.ts +6 -2
- package/lib/apps/publish-piral.js +30 -26
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/remove-piral-instance-pilet.d.ts +22 -0
- package/lib/apps/remove-piral-instance-pilet.js +52 -0
- package/lib/apps/remove-piral-instance-pilet.js.map +1 -0
- package/lib/apps/run-emulator-piral.d.ts +34 -0
- package/lib/apps/run-emulator-piral.js +91 -0
- package/lib/apps/run-emulator-piral.js.map +1 -0
- package/lib/apps/upgrade-pilet.d.ts +6 -2
- package/lib/apps/upgrade-pilet.js +41 -43
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.d.ts +2 -2
- package/lib/apps/upgrade-piral.js +21 -20
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/apps/validate-pilet.js +30 -36
- package/lib/apps/validate-pilet.js.map +1 -1
- package/lib/apps/validate-piral.js +13 -10
- package/lib/apps/validate-piral.js.map +1 -1
- package/lib/build/bundler-calls.d.ts +3 -0
- package/lib/build/bundler-calls.js +117 -0
- package/lib/build/bundler-calls.js.map +1 -0
- package/lib/build/run-build-pilet.d.ts +1 -0
- package/lib/build/run-build-pilet.js +65 -0
- package/lib/build/run-build-pilet.js.map +1 -0
- package/lib/build/run-build-piral.d.ts +1 -0
- package/lib/build/run-build-piral.js +67 -0
- package/lib/build/run-build-piral.js.map +1 -0
- package/lib/build/run-debug-mono-piral.d.ts +1 -0
- package/lib/build/run-debug-mono-piral.js +70 -0
- package/lib/build/run-debug-mono-piral.js.map +1 -0
- package/lib/build/run-debug-pilet.d.ts +1 -0
- package/lib/build/run-debug-pilet.js +89 -0
- package/lib/build/run-debug-pilet.js.map +1 -0
- package/lib/build/run-debug-piral.d.ts +1 -0
- package/lib/build/run-debug-piral.js +85 -0
- package/lib/build/run-debug-piral.js.map +1 -0
- package/lib/bundler.js +75 -26
- package/lib/bundler.js.map +1 -1
- package/lib/cli.js +7 -4
- package/lib/cli.js.map +1 -1
- package/lib/commands.js +266 -46
- package/lib/commands.js.map +1 -1
- package/lib/common/archive.d.ts +4 -0
- package/lib/common/archive.js +31 -10
- package/lib/common/archive.js.map +1 -1
- package/lib/common/browser.d.ts +2 -1
- package/lib/common/browser.js +17 -8
- package/lib/common/browser.js.map +1 -1
- package/lib/common/clients/index.d.ts +21 -0
- package/lib/common/clients/index.js +48 -0
- package/lib/common/clients/index.js.map +1 -0
- package/lib/common/clients/lerna.d.ts +7 -1
- package/lib/common/clients/lerna.js +93 -7
- package/lib/common/clients/lerna.js.map +1 -1
- package/lib/common/clients/npm.d.ts +6 -1
- package/lib/common/clients/npm.js +66 -18
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnp.d.ts +7 -0
- package/lib/common/clients/pnp.js +104 -0
- package/lib/common/clients/pnp.js.map +1 -0
- package/lib/common/clients/pnpm.d.ts +5 -0
- package/lib/common/clients/pnpm.js +55 -6
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/clients/rush.d.ts +7 -0
- package/lib/common/clients/rush.js +127 -0
- package/lib/common/clients/rush.js.map +1 -0
- package/lib/common/clients/yarn.d.ts +5 -0
- package/lib/common/clients/yarn.js +57 -6
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/compatibility.js +14 -9
- package/lib/common/compatibility.js.map +1 -1
- package/lib/common/config.d.ts +52 -1
- package/lib/common/config.js +10 -30
- package/lib/common/config.js.map +1 -1
- package/lib/common/constants.d.ts +10 -2
- package/lib/common/constants.js +22 -4
- package/lib/common/constants.js.map +1 -1
- package/lib/common/declaration.d.ts +2 -1
- package/lib/common/declaration.js +113 -56
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emoji.d.ts +8 -0
- package/lib/common/emoji.js +10 -1
- package/lib/common/emoji.js.map +1 -1
- package/lib/common/emulator.d.ts +2 -2
- package/lib/common/emulator.js +45 -32
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/enums.d.ts +0 -4
- package/lib/common/enums.js +1 -6
- package/lib/common/enums.js.map +1 -1
- package/lib/common/envs.js +16 -5
- package/lib/common/envs.js.map +1 -1
- package/lib/common/hash.d.ts +1 -0
- package/lib/common/hash.js +8 -3
- package/lib/common/hash.js.map +1 -1
- package/lib/common/http.d.ts +5 -2
- package/lib/common/http.js +65 -23
- package/lib/common/http.js.map +1 -1
- package/lib/common/importmap.d.ts +2 -0
- package/lib/common/importmap.js +202 -0
- package/lib/common/importmap.js.map +1 -0
- package/lib/common/index.d.ts +10 -0
- package/lib/common/index.js +15 -1
- package/lib/common/index.js.map +1 -1
- package/lib/common/info.d.ts +5 -0
- package/lib/common/info.js +9 -2
- package/lib/common/info.js.map +1 -1
- package/lib/common/injectors.d.ts +36 -8
- package/lib/common/injectors.js +46 -19
- package/lib/common/injectors.js.map +1 -1
- package/lib/common/inspect.d.ts +5 -3
- package/lib/common/inspect.js +15 -15
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/interactive.d.ts +9 -0
- package/lib/common/interactive.js +60 -1
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/io.d.ts +9 -3
- package/lib/common/io.js +219 -116
- package/lib/common/io.js.map +1 -1
- package/lib/common/language.d.ts +9 -6
- package/lib/common/language.js +68 -12
- package/lib/common/language.js.map +1 -1
- package/lib/common/log.d.ts +5 -3
- package/lib/common/log.js +34 -48
- package/lib/common/log.js.map +1 -1
- package/lib/common/npm.d.ts +17 -16
- package/lib/common/npm.js +262 -158
- package/lib/common/npm.js.map +1 -1
- package/lib/common/pack.js +47 -26
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.d.ts +43 -20
- package/lib/common/package.js +377 -213
- package/lib/common/package.js.map +1 -1
- package/lib/common/parallel.d.ts +1 -0
- package/lib/common/parallel.js +29 -0
- package/lib/common/parallel.js.map +1 -0
- package/lib/common/patcher.js +20 -20
- package/lib/common/patcher.js.map +1 -1
- package/lib/common/platform.d.ts +13 -0
- package/lib/common/platform.js +29 -0
- package/lib/common/platform.js.map +1 -0
- package/lib/common/port.d.ts +1 -0
- package/lib/common/port.js +14 -4
- package/lib/common/port.js.map +1 -1
- package/lib/common/rules.js +4 -4
- package/lib/common/rules.js.map +1 -1
- package/lib/common/scaffold.d.ts +18 -4
- package/lib/common/scaffold.js +59 -36
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/scripts.js +8 -8
- package/lib/common/scripts.js.map +1 -1
- package/lib/common/shell.d.ts +2 -0
- package/lib/common/shell.js +33 -0
- package/lib/common/shell.js.map +1 -0
- package/lib/common/spec.d.ts +29 -0
- package/lib/common/spec.js +69 -0
- package/lib/common/spec.js.map +1 -0
- package/lib/common/template.d.ts +1 -2
- package/lib/common/template.js +23 -22
- package/lib/common/template.js.map +1 -1
- package/lib/common/url.d.ts +1 -0
- package/lib/common/url.js +17 -0
- package/lib/common/url.js.map +1 -0
- package/lib/common/utils.d.ts +1 -0
- package/lib/common/utils.js +8 -0
- package/lib/common/utils.js.map +1 -0
- package/lib/common/version.d.ts +2 -0
- package/lib/common/version.js +130 -0
- package/lib/common/version.js.map +1 -0
- package/lib/common/watcher.d.ts +13 -0
- package/lib/common/watcher.js +78 -0
- package/lib/common/watcher.js.map +1 -0
- package/lib/external/index.js +59413 -57862
- package/lib/helpers.d.ts +6 -6
- package/lib/helpers.js +10 -25
- package/lib/helpers.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/inject.js +2 -2
- package/lib/inject.js.map +1 -1
- package/lib/injectors/pilet-injector.d.ts +75 -0
- package/lib/injectors/pilet-injector.js +246 -0
- package/lib/injectors/pilet-injector.js.map +1 -0
- package/lib/injectors/{piral.d.ts → piral-injector.d.ts} +10 -2
- package/lib/injectors/piral-injector.js +97 -0
- package/lib/injectors/piral-injector.js.map +1 -0
- package/lib/messages.d.ts +567 -47
- package/lib/messages.js +638 -51
- package/lib/messages.js.map +1 -1
- package/lib/pb-cli.js +1 -1
- package/lib/pb-cli.js.map +1 -1
- package/lib/pilet-cli.js +1 -1
- package/lib/pilet-cli.js.map +1 -1
- package/lib/piral-cli.js +1 -1
- package/lib/piral-cli.js.map +1 -1
- package/lib/platforms/node.d.ts +8 -0
- package/lib/platforms/node.js +30 -0
- package/lib/platforms/node.js.map +1 -0
- package/lib/platforms/web.d.ts +8 -0
- package/lib/platforms/web.js +120 -0
- package/lib/platforms/web.js.map +1 -0
- package/lib/plugin.js +36 -11
- package/lib/plugin.js.map +1 -1
- package/lib/questionnaire.d.ts +1 -1
- package/lib/questionnaire.js +9 -4
- package/lib/questionnaire.js.map +1 -1
- package/lib/release.d.ts +1 -1
- package/lib/release.js +38 -6
- package/lib/release.js.map +1 -1
- package/lib/resolvers.js +13 -13
- package/lib/resolvers.js.map +1 -1
- package/lib/rules/index.js +8 -8
- package/lib/rules/index.js.map +1 -1
- package/lib/rules/pilet-has-externals-as-peers.d.ts +1 -1
- package/lib/rules/pilet-has-externals-as-peers.js +9 -7
- package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
- package/lib/rules/pilet-has-no-self-reference.d.ts +1 -1
- package/lib/rules/pilet-has-no-self-reference.js +2 -2
- package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
- package/lib/rules/pilet-has-no-third-party-dependency.d.ts +1 -1
- package/lib/rules/pilet-stays-small.d.ts +1 -1
- package/lib/rules/pilet-stays-small.js +4 -4
- package/lib/rules/pilet-stays-small.js.map +1 -1
- package/lib/rules/pilet-uses-latest-piral.d.ts +1 -1
- package/lib/rules/pilet-uses-latest-piral.js +18 -9
- package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
- package/lib/rules/piral-depends-on-piral.d.ts +1 -1
- package/lib/rules/piral-entry-ends-with-html.d.ts +1 -1
- package/lib/rules/piral-entry-ends-with-html.js +1 -1
- package/lib/rules/piral-entry-ends-with-html.js.map +1 -1
- package/lib/rules/piral-has-valid-devDependencies.d.ts +1 -1
- package/lib/rules/piral-has-valid-externals.d.ts +1 -1
- package/lib/rules/piral-has-valid-externals.js +10 -24
- package/lib/rules/piral-has-valid-externals.js.map +1 -1
- package/lib/rules/piral-has-valid-files.d.ts +1 -1
- package/lib/rules/piral-has-valid-files.js +5 -5
- package/lib/rules/piral-has-valid-files.js.map +1 -1
- package/lib/rules/piral-has-valid-scripts.d.ts +1 -1
- package/lib/runner.js +1 -1
- package/lib/runner.js.map +1 -1
- package/lib/select.js +6 -6
- package/lib/select.js.map +1 -1
- package/lib/types/common.d.ts +88 -8
- package/lib/types/common.js.map +1 -1
- package/lib/types/index.js +5 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/internal.d.ts +12 -13
- package/lib/types/public.d.ts +89 -23
- package/package.json +19 -16
- package/src/apps/add-piral-instance-pilet.ts +98 -0
- package/src/apps/build-pilet.ts +286 -38
- package/src/apps/build-piral.test.ts +20 -7
- package/src/apps/build-piral.ts +90 -39
- package/src/apps/debug-pilet.ts +229 -123
- package/src/apps/debug-piral.ts +121 -68
- package/src/apps/declaration-piral.ts +4 -2
- package/src/apps/index.ts +3 -0
- package/src/apps/new-pilet.test.ts +28 -11
- package/src/apps/new-pilet.ts +60 -48
- package/src/apps/new-piral.test.ts +25 -13
- package/src/apps/new-piral.ts +43 -19
- package/src/apps/pack-pilet.test.ts +2 -2
- package/src/apps/pack-pilet.ts +12 -10
- package/src/apps/publish-pilet.ts +148 -43
- package/src/apps/publish-piral.ts +38 -11
- package/src/apps/remove-piral-instance-pilet.ts +92 -0
- package/src/apps/run-emulator-piral.ts +154 -0
- package/src/apps/upgrade-pilet.ts +37 -31
- package/src/apps/upgrade-piral.ts +9 -7
- package/src/apps/validate-pilet.ts +30 -22
- package/src/apps/validate-piral.ts +5 -2
- package/src/build/bundler-calls.ts +133 -0
- package/src/build/run-build-pilet.ts +91 -0
- package/src/build/run-build-piral.ts +93 -0
- package/src/build/run-debug-mono-piral.ts +86 -0
- package/src/build/run-debug-pilet.ts +116 -0
- package/src/build/run-debug-piral.ts +105 -0
- package/src/bundler.test.ts +86 -68
- package/src/bundler.ts +74 -19
- package/src/cli.ts +6 -2
- package/src/commands.ts +273 -44
- package/src/common/archive.test.ts +51 -45
- package/src/common/archive.ts +28 -1
- package/src/common/browser.test.ts +20 -10
- package/src/common/browser.ts +13 -6
- package/src/common/clients/index.ts +41 -0
- package/src/common/clients/lerna.ts +85 -1
- package/src/common/clients/npm.ts +56 -14
- package/src/common/clients/pnp.ts +84 -0
- package/src/common/clients/pnpm.ts +45 -1
- package/src/common/clients/rush.ts +118 -0
- package/src/common/clients/yarn.ts +49 -3
- package/src/common/compatibility.ts +8 -1
- package/src/common/config.ts +57 -22
- package/src/common/constants.ts +21 -3
- package/src/common/declaration.ts +124 -50
- package/src/common/emoji.ts +9 -0
- package/src/common/emulator.ts +43 -23
- package/src/common/enums.ts +0 -5
- package/src/common/envs.ts +15 -3
- package/src/common/hash.ts +5 -0
- package/src/common/http.test.ts +76 -64
- package/src/common/http.ts +88 -24
- package/src/common/importmap.ts +242 -0
- package/src/common/index.ts +10 -0
- package/src/common/info.ts +9 -1
- package/src/common/injectors.ts +49 -22
- package/src/common/inspect.ts +13 -14
- package/src/common/interactive.test.ts +6 -0
- package/src/common/interactive.ts +69 -1
- package/src/common/io.ts +199 -82
- package/src/common/language.ts +87 -10
- package/src/common/log.ts +32 -46
- package/src/common/npm.test.ts +187 -166
- package/src/common/npm.ts +263 -119
- package/src/common/pack.test.ts +11 -13
- package/src/common/pack.ts +60 -21
- package/src/common/package.test.ts +59 -49
- package/src/common/package.ts +406 -167
- package/src/common/parallel.test.ts +28 -0
- package/src/common/parallel.ts +21 -0
- package/src/common/platform.ts +31 -0
- package/src/common/port.test.ts +4 -1
- package/src/common/port.ts +10 -0
- package/src/common/rules.test.ts +3 -3
- package/src/common/scaffold.ts +69 -41
- package/src/common/scripts.ts +5 -4
- package/src/common/shell.ts +34 -0
- package/src/common/spec.ts +69 -0
- package/src/common/template.ts +20 -18
- package/src/common/url.test.ts +28 -0
- package/src/common/url.ts +15 -0
- package/src/common/utils.ts +3 -0
- package/src/common/version.test.ts +233 -0
- package/src/common/version.ts +142 -0
- package/src/common/watcher.ts +89 -0
- package/src/external/index.test.ts +2 -2
- package/src/external/index.ts +7 -3
- package/src/external/resolve.ts +29 -0
- package/src/helpers.test.ts +2 -22
- package/src/helpers.ts +21 -30
- package/src/injectors/{pilet.test.ts → pilet-injector.test.ts} +13 -4
- package/src/injectors/pilet-injector.ts +346 -0
- package/src/injectors/{piral.test.ts → piral-injector.test.ts} +14 -5
- package/src/injectors/piral-injector.ts +130 -0
- package/src/messages.ts +649 -63
- package/src/platforms/node.ts +16 -0
- package/src/platforms/web.ts +148 -0
- package/src/plugin.ts +34 -5
- package/src/questionnaire.ts +17 -3
- package/src/release.ts +47 -5
- package/src/rules/index.ts +1 -1
- package/src/rules/pilet-has-externals-as-peers.test.ts +3 -2
- package/src/rules/pilet-has-externals-as-peers.ts +9 -7
- package/src/rules/pilet-has-no-self-reference.ts +1 -1
- package/src/rules/pilet-stays-small.ts +1 -1
- package/src/rules/pilet-uses-latest-piral.ts +22 -12
- package/src/rules/piral-has-valid-externals.ts +10 -29
- package/src/types/common.ts +99 -9
- package/src/types/internal.ts +14 -14
- package/src/types/public.ts +93 -27
- package/lib/external/child.js +0 -144
- package/lib/external/classes.trie +0 -0
- package/lib/external/xdg-open +0 -1066
- package/lib/injectors/pilet.d.ts +0 -47
- package/lib/injectors/pilet.js +0 -187
- package/lib/injectors/pilet.js.map +0 -1
- package/lib/injectors/piral.js +0 -62
- package/lib/injectors/piral.js.map +0 -1
- package/src/injectors/pilet.ts +0 -219
- package/src/injectors/piral.ts +0 -76
- package/templates/piral-index.js.ejs +0 -16
|
@@ -45,52 +45,58 @@ jest.mock('path', () =>
|
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
const fileNotFoundError = 'File not found!';
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
resolve(true);
|
|
53
|
-
} else {
|
|
54
|
-
reject(fileNotFoundError);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
extract: (options: ExtractOptions & FileOptions, fileList?: ReadonlyArray<string>) => {
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
if (options.file && options.file.includes('foo.tgz')) {
|
|
61
|
-
resolve(true);
|
|
62
|
-
} else {
|
|
63
|
-
reject(fileNotFoundError);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
Parse: () => {
|
|
68
|
-
return {
|
|
69
|
-
position: 0,
|
|
70
|
-
_stream: new Stream(),
|
|
71
|
-
_ended: false,
|
|
72
|
-
_streamEnd: () => {
|
|
73
|
-
this._ended = true;
|
|
74
|
-
console.log('_streamEnd');
|
|
75
|
-
},
|
|
76
|
-
process: (c: Buffer) => {
|
|
77
|
-
console.log('process');
|
|
78
|
-
},
|
|
79
|
-
_startEntry: (c: Buffer) => {
|
|
80
|
-
console.log('_startEntry');
|
|
81
|
-
},
|
|
82
|
-
on: (event: string, listener: (...args: any[]) => {}) => {
|
|
83
|
-
console.log(`on event: ${event}`);
|
|
84
|
-
},
|
|
85
|
-
once: (event: string, listener: (...args: any[]) => {}) => {
|
|
86
|
-
console.log(`once event: ${event}`);
|
|
87
|
-
},
|
|
88
|
-
emit: (event: string | symbol, ...args: any[]) => {
|
|
89
|
-
console.log(`emit event: ${event.toString()}`);
|
|
90
|
-
return true;
|
|
91
|
-
},
|
|
92
|
-
} as any;
|
|
48
|
+
|
|
49
|
+
jest.mock('../external', () => ({
|
|
50
|
+
ora() {
|
|
51
|
+
return {};
|
|
93
52
|
},
|
|
53
|
+
tar: {
|
|
54
|
+
create: (options: CreateOptions & FileOptions, fileList: ReadonlyArray<string>) => {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
if (options.file && options.file == 'foo.txt') {
|
|
57
|
+
resolve(true);
|
|
58
|
+
} else {
|
|
59
|
+
reject(fileNotFoundError);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
extract: (options: ExtractOptions & FileOptions, fileList?: ReadonlyArray<string>) => {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
if (options.file && options.file.includes('foo.tgz')) {
|
|
66
|
+
resolve(true);
|
|
67
|
+
} else {
|
|
68
|
+
reject(fileNotFoundError);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
Parse: () => {
|
|
73
|
+
return {
|
|
74
|
+
position: 0,
|
|
75
|
+
_stream: new Stream(),
|
|
76
|
+
_ended: false,
|
|
77
|
+
_streamEnd: () => {
|
|
78
|
+
this._ended = true;
|
|
79
|
+
console.log('_streamEnd');
|
|
80
|
+
},
|
|
81
|
+
process: (c: Buffer) => {
|
|
82
|
+
console.log('process');
|
|
83
|
+
},
|
|
84
|
+
_startEntry: (c: Buffer) => {
|
|
85
|
+
console.log('_startEntry');
|
|
86
|
+
},
|
|
87
|
+
on: (event: string, listener: (...args: any[]) => {}) => {
|
|
88
|
+
console.log(`on event: ${event}`);
|
|
89
|
+
},
|
|
90
|
+
once: (event: string, listener: (...args: any[]) => {}) => {
|
|
91
|
+
console.log(`once event: ${event}`);
|
|
92
|
+
},
|
|
93
|
+
emit: (event: string | symbol, ...args: any[]) => {
|
|
94
|
+
console.log(`emit event: ${event.toString()}`);
|
|
95
|
+
return true;
|
|
96
|
+
},
|
|
97
|
+
} as any;
|
|
98
|
+
},
|
|
99
|
+
}
|
|
94
100
|
}));
|
|
95
101
|
|
|
96
102
|
describe('Archive Module', () => {
|
package/src/common/archive.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { resolve, relative } from 'path';
|
|
2
1
|
import { createGunzip } from 'zlib';
|
|
3
2
|
import { EventEmitter } from 'events';
|
|
3
|
+
import { createWriteStream } from 'fs';
|
|
4
|
+
import { resolve, relative } from 'path';
|
|
4
5
|
import { log } from './log';
|
|
5
6
|
import { tar } from '../external';
|
|
6
7
|
import { PackageFiles } from '../types';
|
|
@@ -11,6 +12,32 @@ interface ReadEntry extends EventEmitter {
|
|
|
11
12
|
ignore: boolean;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Creates an npm-style tgz.
|
|
17
|
+
*/
|
|
18
|
+
export function createTgz(file: string, cwd: string, files: Array<string>) {
|
|
19
|
+
const stream = createWriteStream(file);
|
|
20
|
+
|
|
21
|
+
const tgz = tar.create(
|
|
22
|
+
{
|
|
23
|
+
cwd,
|
|
24
|
+
prefix: 'package/',
|
|
25
|
+
portable: true,
|
|
26
|
+
follow: true,
|
|
27
|
+
gzip: {
|
|
28
|
+
level: 9,
|
|
29
|
+
},
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
mtime: new Date('1985-10-26T08:15:00.000Z'),
|
|
32
|
+
},
|
|
33
|
+
files,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
tgz.pipe(stream, { end: true });
|
|
37
|
+
|
|
38
|
+
return new Promise((finish) => stream.on('close', finish));
|
|
39
|
+
}
|
|
40
|
+
|
|
14
41
|
export function createTarball(sourceDir: string, targetDir: string, targetFile: string) {
|
|
15
42
|
const folder = relative(targetDir, sourceDir);
|
|
16
43
|
log('generalDebug_0003', `Create archive "${targetFile}" in "${targetDir}" containing "${folder}".`);
|
|
@@ -2,23 +2,33 @@ import { openBrowser } from './browser';
|
|
|
2
2
|
|
|
3
3
|
let error = false;
|
|
4
4
|
|
|
5
|
-
jest.mock('
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
5
|
+
jest.mock('../external', () => ({
|
|
6
|
+
rc(_, cfg) {
|
|
7
|
+
return cfg;
|
|
8
|
+
},
|
|
9
|
+
ora() {
|
|
10
|
+
return {
|
|
11
|
+
fail() {},
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
open() {
|
|
15
|
+
if (error) {
|
|
16
|
+
throw new Error('Error occured');
|
|
17
|
+
} else {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
12
22
|
|
|
13
23
|
describe('Browser Module', () => {
|
|
14
24
|
it('opens browser successfully', async () => {
|
|
15
25
|
error = false;
|
|
16
|
-
await openBrowser(false, 1234).then((result) => expect(result).toBeUndefined());
|
|
17
|
-
await openBrowser(true, 1234).then((result) => expect(result).toBeUndefined());
|
|
26
|
+
await openBrowser(false, 1234, '/').then((result) => expect(result).toBeUndefined());
|
|
27
|
+
await openBrowser(true, 1234, '/').then((result) => expect(result).toBeUndefined());
|
|
18
28
|
});
|
|
19
29
|
|
|
20
30
|
it('handles errored opening', async () => {
|
|
21
31
|
error = true;
|
|
22
|
-
await openBrowser(true, 1234).then((result) => expect(result).toBeUndefined());
|
|
32
|
+
await openBrowser(true, 1234, '/').then((result) => expect(result).toBeUndefined());
|
|
23
33
|
});
|
|
24
34
|
});
|
package/src/common/browser.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { log } from './log';
|
|
2
|
+
import { config } from './config';
|
|
2
3
|
import { open } from '../external';
|
|
3
4
|
|
|
4
|
-
export async function
|
|
5
|
+
export async function openBrowserAt(address: string) {
|
|
6
|
+
try {
|
|
7
|
+
await open(address, undefined);
|
|
8
|
+
} catch (err) {
|
|
9
|
+
log('failedToOpenBrowser_0170', err);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function openBrowser(shouldOpen: boolean, port: number, path: string, https?: boolean) {
|
|
5
14
|
if (shouldOpen) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
log('failedToOpenBrowser_0170', err);
|
|
10
|
-
}
|
|
15
|
+
const scheme = https ? 'https' : 'http';
|
|
16
|
+
const address = `${scheme}://${config.host}:${port}${path}`;
|
|
17
|
+
await openBrowserAt(address);
|
|
11
18
|
}
|
|
12
19
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { dirname, resolve } from 'path';
|
|
2
|
+
import { findFile } from '../io';
|
|
3
|
+
|
|
4
|
+
import * as lerna from './lerna';
|
|
5
|
+
import * as npm from './npm';
|
|
6
|
+
import * as pnp from './pnp';
|
|
7
|
+
import * as pnpm from './pnpm';
|
|
8
|
+
import * as rush from './rush';
|
|
9
|
+
import * as yarn from './yarn';
|
|
10
|
+
|
|
11
|
+
export const clients = {
|
|
12
|
+
lerna,
|
|
13
|
+
npm,
|
|
14
|
+
pnp,
|
|
15
|
+
pnpm,
|
|
16
|
+
rush,
|
|
17
|
+
yarn,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type ClientName = keyof typeof clients;
|
|
21
|
+
|
|
22
|
+
const directClients = ['npm', 'pnp', 'yarn', 'pnpm'];
|
|
23
|
+
|
|
24
|
+
export function isWrapperClient(client: ClientName) {
|
|
25
|
+
return !directClients.includes(client);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function detectClients(root: string) {
|
|
29
|
+
const packageJson = await findFile(resolve(root, '..'), 'package.json');
|
|
30
|
+
const stopDir = packageJson ? dirname(packageJson) : undefined;
|
|
31
|
+
|
|
32
|
+
return await Promise.all(
|
|
33
|
+
Object.keys(clients).map(async (client: ClientName) => {
|
|
34
|
+
const result = await clients[client].detectClient(root, stopDir);
|
|
35
|
+
return {
|
|
36
|
+
client,
|
|
37
|
+
result,
|
|
38
|
+
};
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -1,17 +1,101 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { log } from '../log';
|
|
3
|
+
import { findFile, readJson, writeJson } from '../io';
|
|
3
4
|
import { runCommand } from '../scripts';
|
|
4
5
|
import { MemoryStream } from '../MemoryStream';
|
|
5
6
|
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
6
9
|
function runLernaProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
7
10
|
log('generalDebug_0003', 'Starting the Lerna process ...');
|
|
8
11
|
const cwd = resolve(process.cwd(), target);
|
|
9
12
|
return runCommand('lerna', args, cwd, output);
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
function convert(flags: Array<string>) {
|
|
16
|
+
return flags.map((flag) => {
|
|
17
|
+
switch (flag) {
|
|
18
|
+
case '--save-exact':
|
|
19
|
+
return '--exact';
|
|
20
|
+
case '--save-dev':
|
|
21
|
+
return '--dev';
|
|
22
|
+
case '--no-save':
|
|
23
|
+
// unfortunately no
|
|
24
|
+
return '';
|
|
25
|
+
default:
|
|
26
|
+
return flag;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Client interface functions:
|
|
32
|
+
|
|
33
|
+
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
13
34
|
const ms = new MemoryStream();
|
|
14
35
|
await runLernaProcess(['bootstrap', ...flags], target, ms);
|
|
15
36
|
log('generalDebug_0003', `Lerna bootstrap result: ${ms.value}`);
|
|
16
37
|
return ms.value;
|
|
17
38
|
}
|
|
39
|
+
|
|
40
|
+
export async function uninstallPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
41
|
+
const ms = new MemoryStream();
|
|
42
|
+
// at the moment not supported by Lerna directly
|
|
43
|
+
// workaround is to manipulate the package.json directly and bootstrap again...
|
|
44
|
+
const packageData = await readJson(target, 'package.json');
|
|
45
|
+
|
|
46
|
+
if (packageData.dependencies && packageRef in packageData.dependencies) {
|
|
47
|
+
packageData.dependencies[packageRef] = undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (packageData.devDependencies && packageRef in packageData.devDependencies) {
|
|
51
|
+
packageData.devDependencies[packageRef] = undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (packageData.peerDependencies && packageRef in packageData.peerDependencies) {
|
|
55
|
+
packageData.peerDependencies[packageRef] = undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await writeJson(target, 'package.json', packageData, true);
|
|
59
|
+
await runLernaProcess(['bootstrap'], target, ms);
|
|
60
|
+
log('generalDebug_0003', `Lerna bootstrap (after remove) package result: ${ms.value}`);
|
|
61
|
+
return ms.value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
65
|
+
const ms = new MemoryStream();
|
|
66
|
+
await runLernaProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
67
|
+
log('generalDebug_0003', `Lerna add package result: ${ms.value}`);
|
|
68
|
+
return ms.value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function detectClient(root: string, stopDir = resolve(root, '/')) {
|
|
72
|
+
return !!(await findFile(root, 'lerna.json', stopDir));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function initProject(projectName: string, target: string) {}
|
|
76
|
+
|
|
77
|
+
export async function isProject(root: string, packageRef: string) {
|
|
78
|
+
const projects = await listProjects(root);
|
|
79
|
+
|
|
80
|
+
if (Array.isArray(projects)) {
|
|
81
|
+
return projects?.some((p) => p.name === packageRef) ?? false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Functions to exclusively use from lerna client:
|
|
88
|
+
|
|
89
|
+
export async function listProjects(target: string) {
|
|
90
|
+
const ms = new MemoryStream();
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
await runLernaProcess(['list', '--json', '-p'], target, ms);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
log('generalDebug_0003', `lerna list error: ${e}`);
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
log('generalDebug_0003', `lerna list project result: ${ms.value}`);
|
|
100
|
+
return JSON.parse(ms.value);
|
|
101
|
+
}
|
|
@@ -1,60 +1,101 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { log } from '../log';
|
|
3
|
+
import { findFile } from '../io';
|
|
3
4
|
import { runCommand } from '../scripts';
|
|
4
5
|
import { MemoryStream } from '../MemoryStream';
|
|
5
6
|
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
6
9
|
function runNpmProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
7
|
-
log('generalDebug_0003', 'Starting the
|
|
10
|
+
log('generalDebug_0003', 'Starting the npm process ...');
|
|
8
11
|
const cwd = resolve(process.cwd(), target);
|
|
9
12
|
return runCommand('npm', args, cwd, output);
|
|
10
13
|
}
|
|
11
14
|
|
|
15
|
+
// Client interface functions:
|
|
16
|
+
|
|
12
17
|
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
13
18
|
const ms = new MemoryStream();
|
|
14
19
|
await runNpmProcess(['install', '--legacy-peer-deps', ...flags], target, ms);
|
|
15
|
-
log('generalDebug_0003', `
|
|
20
|
+
log('generalDebug_0003', `npm install dependencies result: ${ms.value}`);
|
|
16
21
|
return ms.value;
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
export async function
|
|
24
|
+
export async function uninstallPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
20
25
|
const ms = new MemoryStream();
|
|
21
|
-
await runNpmProcess(['
|
|
22
|
-
log('generalDebug_0003', `
|
|
26
|
+
await runNpmProcess(['uninstall', packageRef, ...flags], target, ms);
|
|
27
|
+
log('generalDebug_0003', `npm uninstall package result: ${ms.value}`);
|
|
23
28
|
return ms.value;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
27
32
|
const ms = new MemoryStream();
|
|
28
33
|
await runNpmProcess(['install', packageRef, '--legacy-peer-deps', ...flags], target, ms);
|
|
29
|
-
log('generalDebug_0003', `
|
|
34
|
+
log('generalDebug_0003', `npm install package result: ${ms.value}`);
|
|
35
|
+
return ms.value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function detectClient(root: string, stopDir = resolve(root, '/')) {
|
|
39
|
+
return !!(await findFile(root, 'package-lock.json', stopDir));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function isProject(root: string, packageRef: string) {
|
|
43
|
+
const details = await listPackage(packageRef, root);
|
|
44
|
+
const packageDetails = details?.dependencies?.[packageRef];
|
|
45
|
+
|
|
46
|
+
if (packageDetails && typeof packageDetails.resolved === 'string') {
|
|
47
|
+
return packageDetails.resolved.startsWith('file:');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function initProject(projectName: string, target: string) {}
|
|
54
|
+
|
|
55
|
+
// Functions to exclusively use from npm client:
|
|
56
|
+
|
|
57
|
+
export async function loginUser() {
|
|
58
|
+
await runNpmProcess(['login'], '.');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function unpackPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
62
|
+
const ms = new MemoryStream();
|
|
63
|
+
await runNpmProcess(['pack', packageRef, ...flags], target, ms);
|
|
64
|
+
log('generalDebug_0003', `npm (un)pack result: ${ms.value}`);
|
|
30
65
|
return ms.value;
|
|
31
66
|
}
|
|
32
67
|
|
|
33
68
|
export async function createPackage(target = '.', ...flags: Array<string>) {
|
|
34
69
|
const ms = new MemoryStream();
|
|
35
70
|
await runNpmProcess(['pack', ...flags], target, ms);
|
|
36
|
-
log('generalDebug_0003', `
|
|
71
|
+
log('generalDebug_0003', `npm pack result: ${ms.value}`);
|
|
37
72
|
return ms.value;
|
|
38
73
|
}
|
|
39
74
|
|
|
40
75
|
export async function publishPackage(target = '.', file = '*.tgz', ...flags: Array<string>) {
|
|
41
76
|
const ms = new MemoryStream();
|
|
42
77
|
await runNpmProcess(['publish', file, ...flags], target, ms);
|
|
43
|
-
log('generalDebug_0003', `
|
|
78
|
+
log('generalDebug_0003', `npm publish result: ${ms.value}`);
|
|
44
79
|
return ms.value;
|
|
45
80
|
}
|
|
46
81
|
|
|
47
82
|
export async function findSpecificVersion(packageName: string, version: string) {
|
|
48
83
|
const ms = new MemoryStream();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
await runNpmProcess(['show', packageName, 'version', '--tag', version], '.', ms);
|
|
87
|
+
log('generalDebug_0003', `npm show result: ${ms.value}`);
|
|
88
|
+
return ms.value;
|
|
89
|
+
} catch (ex) {
|
|
90
|
+
log('generalDebug_0003', `npm show result: ${ex}`);
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
52
93
|
}
|
|
53
94
|
|
|
54
95
|
export async function findTarball(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
55
96
|
const ms = new MemoryStream();
|
|
56
97
|
await runNpmProcess(['view', packageRef, 'dist.tarball', ...flags], target, ms);
|
|
57
|
-
log('generalDebug_0003', `
|
|
98
|
+
log('generalDebug_0003', `npm view packageRef result: ${ms.value}`);
|
|
58
99
|
return ms.value;
|
|
59
100
|
}
|
|
60
101
|
|
|
@@ -64,9 +105,10 @@ export async function listPackage(packageRef: string, target = '.', ...flags: Ar
|
|
|
64
105
|
try {
|
|
65
106
|
await runNpmProcess(['ls', packageRef, '--json', '--depth', '0', ...flags], target, ms);
|
|
66
107
|
} catch (e) {
|
|
67
|
-
log('generalDebug_0003', `
|
|
108
|
+
log('generalDebug_0003', `npm ls packageRef error: ${e}`);
|
|
109
|
+
return {};
|
|
68
110
|
}
|
|
69
111
|
|
|
70
|
-
log('generalDebug_0003', `
|
|
112
|
+
log('generalDebug_0003', `npm ls packageRef result: ${ms.value}`);
|
|
71
113
|
return JSON.parse(ms.value);
|
|
72
114
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { log } from '../log';
|
|
3
|
+
import { findFile } from '../io';
|
|
4
|
+
import { runCommand } from '../scripts';
|
|
5
|
+
import { MemoryStream } from '../MemoryStream';
|
|
6
|
+
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
9
|
+
function runYarnProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
10
|
+
log('generalDebug_0003', 'Starting the Yarn PnP process ...');
|
|
11
|
+
const cwd = resolve(process.cwd(), target);
|
|
12
|
+
return runCommand('yarn', args, cwd, output);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function convert(flags: Array<string>) {
|
|
16
|
+
return flags.map((flag) => {
|
|
17
|
+
switch (flag) {
|
|
18
|
+
case '--save-exact':
|
|
19
|
+
return '--exact';
|
|
20
|
+
case '--save-dev':
|
|
21
|
+
return '--dev';
|
|
22
|
+
case '--no-save':
|
|
23
|
+
// unfortunately no (https://github.com/yarnpkg/yarn/issues/1743)
|
|
24
|
+
return '';
|
|
25
|
+
default:
|
|
26
|
+
return flag;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Client interface functions:
|
|
32
|
+
|
|
33
|
+
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
34
|
+
const ms = new MemoryStream();
|
|
35
|
+
await runYarnProcess(['install', ...convert(flags)], target, ms);
|
|
36
|
+
log('generalDebug_0003', `Yarn PnP install dependencies result: ${ms.value}`);
|
|
37
|
+
return ms.value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function uninstallPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
41
|
+
const ms = new MemoryStream();
|
|
42
|
+
await runYarnProcess(['remove', packageRef, ...convert(flags)], target, ms);
|
|
43
|
+
log('generalDebug_0003', `Yarn PnP remove package result: ${ms.value}`);
|
|
44
|
+
return ms.value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
48
|
+
const ms = new MemoryStream();
|
|
49
|
+
await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
50
|
+
log('generalDebug_0003', `Yarn PnP add package result: ${ms.value}`);
|
|
51
|
+
return ms.value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function detectClient(root: string, stopDir = resolve(root, '/')) {
|
|
55
|
+
return !!(await findFile(root, '.pnp.cjs', stopDir));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function initProject(projectName: string, target: string) {}
|
|
59
|
+
|
|
60
|
+
export async function isProject(root: string, packageRef: string) {
|
|
61
|
+
const details = await listProjects(root);
|
|
62
|
+
|
|
63
|
+
if (typeof details === 'object') {
|
|
64
|
+
return typeof details?.[packageRef]?.location === 'string';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Functions to exclusively use from yarn client:
|
|
71
|
+
|
|
72
|
+
export async function listProjects(target: string) {
|
|
73
|
+
const ms = new MemoryStream();
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
await runYarnProcess(['workspaces', 'info'], target, ms);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
log('generalDebug_0003', `yarn workspaces error: ${e}`);
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
log('generalDebug_0003', `yarn workspaces result: ${ms.value}`);
|
|
83
|
+
return JSON.parse(ms.value);
|
|
84
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { log } from '../log';
|
|
3
|
+
import { findFile } from '../io';
|
|
3
4
|
import { runCommand } from '../scripts';
|
|
4
5
|
import { MemoryStream } from '../MemoryStream';
|
|
5
6
|
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
6
9
|
function runPnpmProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
7
10
|
log('generalDebug_0003', 'Starting the Pnpm process ...');
|
|
8
11
|
const cwd = resolve(process.cwd(), target);
|
|
@@ -21,6 +24,8 @@ function convert(flags: Array<string>) {
|
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
26
|
|
|
27
|
+
// Client interface functions:
|
|
28
|
+
|
|
24
29
|
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
25
30
|
const ms = new MemoryStream();
|
|
26
31
|
await runPnpmProcess(['install', ...convert(flags)], target, ms);
|
|
@@ -28,9 +33,48 @@ export async function installDependencies(target = '.', ...flags: Array<string>)
|
|
|
28
33
|
return ms.value;
|
|
29
34
|
}
|
|
30
35
|
|
|
36
|
+
export async function uninstallPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
37
|
+
const ms = new MemoryStream();
|
|
38
|
+
await runPnpmProcess(['remove', packageRef, ...convert(flags)], target, ms);
|
|
39
|
+
log('generalDebug_0003', `Pnpm remove package result: ${ms.value}`);
|
|
40
|
+
return ms.value;
|
|
41
|
+
}
|
|
42
|
+
|
|
31
43
|
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
32
44
|
const ms = new MemoryStream();
|
|
33
45
|
await runPnpmProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
34
|
-
log('generalDebug_0003', `Pnpm
|
|
46
|
+
log('generalDebug_0003', `Pnpm add package result: ${ms.value}`);
|
|
35
47
|
return ms.value;
|
|
36
48
|
}
|
|
49
|
+
|
|
50
|
+
export async function detectClient(root: string, stopDir = resolve(root, '/')) {
|
|
51
|
+
return !!(await findFile(root, ['pnpm-lock.yaml', 'pnpm-workspace.yaml'], stopDir));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function initProject(projectName: string, target: string) {}
|
|
55
|
+
|
|
56
|
+
export async function isProject(root: string, packageRef: string) {
|
|
57
|
+
const projects = await listProjects(root);
|
|
58
|
+
|
|
59
|
+
if (Array.isArray(projects)) {
|
|
60
|
+
return projects?.some((p) => p.name === packageRef) ?? false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Functions to exclusively use from pnpm client:
|
|
67
|
+
|
|
68
|
+
export async function listProjects(target: string) {
|
|
69
|
+
const ms = new MemoryStream();
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
await runPnpmProcess(['list', '--json', '--recursive', '--depth', '0'], target, ms);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
log('generalDebug_0003', `pnpm list error: ${e}`);
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
log('generalDebug_0003', `pnpm list project result: ${ms.value}`);
|
|
79
|
+
return JSON.parse(ms.value);
|
|
80
|
+
}
|