piral-cli 1.0.0-pre.2296 → 1.0.1-beta.5640
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
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { resolve, dirname, isAbsolute, basename } from 'path';
|
|
2
|
+
import { log, fail } from './log';
|
|
3
|
+
import { satisfies, validate } from './version';
|
|
4
|
+
import { computeHash } from './hash';
|
|
5
|
+
import { getHash, readJson, findFile, checkExists, checkIsDirectory } from './io';
|
|
6
|
+
import { tryResolvePackage } from './npm';
|
|
7
|
+
import { SharedDependency, Importmap } from '../types';
|
|
8
|
+
|
|
9
|
+
const shorthandsUrls = ['', '.', '...'];
|
|
10
|
+
|
|
11
|
+
function addLocalDependencies(
|
|
12
|
+
dependencies: Array<SharedDependency>,
|
|
13
|
+
realIdentifier: string,
|
|
14
|
+
identifier: string,
|
|
15
|
+
version: string,
|
|
16
|
+
requireVersion: string,
|
|
17
|
+
entry: string,
|
|
18
|
+
assetName: string,
|
|
19
|
+
) {
|
|
20
|
+
const alias = realIdentifier !== identifier ? realIdentifier : undefined;
|
|
21
|
+
|
|
22
|
+
dependencies.push({
|
|
23
|
+
id: `${identifier}@${version}`,
|
|
24
|
+
requireId: `${identifier}@${requireVersion}`,
|
|
25
|
+
entry,
|
|
26
|
+
name: identifier,
|
|
27
|
+
ref: `${assetName}.js`,
|
|
28
|
+
type: 'local',
|
|
29
|
+
alias,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getDependencyDetails(depName: string): [assetName: string, identifier: string, versionSpec: string] {
|
|
34
|
+
const sep = depName.indexOf('@', 1);
|
|
35
|
+
const version = sep > 0 ? depName.substring(sep + 1) : '';
|
|
36
|
+
const id = sep > 0 ? depName.substring(0, sep) : depName;
|
|
37
|
+
const assetName = (id.startsWith('@') ? id.substring(1) : id).replace(/[\/\.]/g, '-').replace(/(\-)+/, '-');
|
|
38
|
+
return [assetName, id, version];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function getLocalDependencyVersion(
|
|
42
|
+
packageJson: string,
|
|
43
|
+
depName: string,
|
|
44
|
+
versionSpec: string,
|
|
45
|
+
): Promise<[realIdentifier: string, offeredVersion: string, requiredVersion: string]> {
|
|
46
|
+
const packageDir = dirname(packageJson);
|
|
47
|
+
const packageFile = basename(packageJson);
|
|
48
|
+
const details = await readJson(packageDir, packageFile);
|
|
49
|
+
|
|
50
|
+
if (versionSpec) {
|
|
51
|
+
if (!validate(versionSpec)) {
|
|
52
|
+
fail('importMapVersionSpecInvalid_0026', depName);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!satisfies(details.version, versionSpec)) {
|
|
56
|
+
fail('importMapVersionSpecNotSatisfied_0025', depName, details.version);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return [details.name, details.version, versionSpec];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return [details.name, details.version, details.version];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function getInheritedDependencies(inheritedImport: string, dir: string): Promise<Array<SharedDependency>> {
|
|
66
|
+
const packageJson = tryResolvePackage(`${inheritedImport}/package.json`, dir);
|
|
67
|
+
|
|
68
|
+
if (packageJson) {
|
|
69
|
+
const packageDir = dirname(packageJson);
|
|
70
|
+
const packageDetails = await readJson(packageDir, 'package.json');
|
|
71
|
+
return readImportmap(packageDir, packageDetails, true);
|
|
72
|
+
} else {
|
|
73
|
+
const directImportmap = tryResolvePackage(inheritedImport, dir);
|
|
74
|
+
|
|
75
|
+
if (directImportmap) {
|
|
76
|
+
const baseDir = dirname(directImportmap);
|
|
77
|
+
const content = await readJson(baseDir, basename(directImportmap));
|
|
78
|
+
return await resolveImportmap(baseDir, content);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function resolveImportmap(dir: string, importmap: Importmap): Promise<Array<SharedDependency>> {
|
|
86
|
+
const dependencies: Array<SharedDependency> = [];
|
|
87
|
+
const sharedImports = importmap?.imports;
|
|
88
|
+
const inheritedImports = importmap?.inherit;
|
|
89
|
+
|
|
90
|
+
if (typeof sharedImports === 'object' && sharedImports) {
|
|
91
|
+
for (const depName of Object.keys(sharedImports)) {
|
|
92
|
+
const url = sharedImports[depName];
|
|
93
|
+
const [assetName, identifier, versionSpec] = getDependencyDetails(depName);
|
|
94
|
+
|
|
95
|
+
if (typeof url !== 'string') {
|
|
96
|
+
log('generalInfo_0000', `The value of "${depName}" in the importmap is not a string and will be ignored.`);
|
|
97
|
+
} else if (/^https?:\/\//.test(url)) {
|
|
98
|
+
const hash = computeHash(url).substring(0, 7);
|
|
99
|
+
|
|
100
|
+
dependencies.push({
|
|
101
|
+
id: `${identifier}@${hash}`,
|
|
102
|
+
requireId: `${identifier}@${hash}`,
|
|
103
|
+
entry: url,
|
|
104
|
+
name: identifier,
|
|
105
|
+
ref: url,
|
|
106
|
+
type: 'remote',
|
|
107
|
+
});
|
|
108
|
+
} else if (url === identifier || shorthandsUrls.includes(url)) {
|
|
109
|
+
const entry = tryResolvePackage(identifier, dir);
|
|
110
|
+
|
|
111
|
+
if (entry) {
|
|
112
|
+
const packageJson = await findFile(dirname(entry), 'package.json');
|
|
113
|
+
const [realIdentifier, version, requireVersion] = await getLocalDependencyVersion(
|
|
114
|
+
packageJson,
|
|
115
|
+
depName,
|
|
116
|
+
versionSpec,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
addLocalDependencies(dependencies, realIdentifier, identifier, version, requireVersion, entry, assetName);
|
|
120
|
+
} else {
|
|
121
|
+
fail('importMapReferenceNotFound_0027', dir, identifier);
|
|
122
|
+
}
|
|
123
|
+
} else if (!url.startsWith('.') && !isAbsolute(url)) {
|
|
124
|
+
const entry = tryResolvePackage(url, dir);
|
|
125
|
+
|
|
126
|
+
if (entry) {
|
|
127
|
+
const packageJson = await findFile(dirname(entry), 'package.json');
|
|
128
|
+
const [realIdentifier, version, requireVersion] = await getLocalDependencyVersion(
|
|
129
|
+
packageJson,
|
|
130
|
+
depName,
|
|
131
|
+
versionSpec,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
addLocalDependencies(dependencies, realIdentifier, identifier, version, requireVersion, entry, assetName);
|
|
135
|
+
} else {
|
|
136
|
+
fail('importMapReferenceNotFound_0027', dir, url);
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
const entry = resolve(dir, url);
|
|
140
|
+
const exists = await checkExists(entry);
|
|
141
|
+
|
|
142
|
+
if (exists) {
|
|
143
|
+
const isDirectory = await checkIsDirectory(entry);
|
|
144
|
+
const packageJson = isDirectory
|
|
145
|
+
? resolve(entry, 'package.json')
|
|
146
|
+
: await findFile(dirname(entry), 'package.json');
|
|
147
|
+
const packageJsonExists = await checkExists(packageJson);
|
|
148
|
+
|
|
149
|
+
if (packageJsonExists) {
|
|
150
|
+
const [realIdentifier, version, requireVersion] = await getLocalDependencyVersion(
|
|
151
|
+
packageJson,
|
|
152
|
+
depName,
|
|
153
|
+
versionSpec,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
addLocalDependencies(
|
|
157
|
+
dependencies,
|
|
158
|
+
realIdentifier,
|
|
159
|
+
identifier,
|
|
160
|
+
version,
|
|
161
|
+
requireVersion,
|
|
162
|
+
isDirectory ? tryResolvePackage(entry, dir) : entry,
|
|
163
|
+
assetName,
|
|
164
|
+
);
|
|
165
|
+
} else if (isDirectory) {
|
|
166
|
+
fail('importMapReferenceNotFound_0027', entry, 'package.json');
|
|
167
|
+
} else {
|
|
168
|
+
const hash = await getHash(entry);
|
|
169
|
+
|
|
170
|
+
dependencies.push({
|
|
171
|
+
id: `${identifier}@${hash}`,
|
|
172
|
+
requireId: `${identifier}@${hash}`,
|
|
173
|
+
entry,
|
|
174
|
+
name: identifier,
|
|
175
|
+
ref: `${assetName}.js`,
|
|
176
|
+
type: 'local',
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
fail('importMapReferenceNotFound_0027', dir, url);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (Array.isArray(inheritedImports)) {
|
|
187
|
+
for (const inheritedImport of inheritedImports) {
|
|
188
|
+
const otherDependencies = await getInheritedDependencies(inheritedImport, dir);
|
|
189
|
+
|
|
190
|
+
for (const dependency of otherDependencies) {
|
|
191
|
+
const entry = dependencies.find((dep) => dep.name === dependency.name);
|
|
192
|
+
|
|
193
|
+
if (!entry) {
|
|
194
|
+
dependencies.push({
|
|
195
|
+
...dependency,
|
|
196
|
+
parents: [inheritedImport],
|
|
197
|
+
});
|
|
198
|
+
} else if (Array.isArray(entry.parents)) {
|
|
199
|
+
entry.parents.push(inheritedImport);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return dependencies;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export async function readImportmap(
|
|
209
|
+
dir: string,
|
|
210
|
+
packageDetails: any,
|
|
211
|
+
inherited = false,
|
|
212
|
+
): Promise<Array<SharedDependency>> {
|
|
213
|
+
const importmap = packageDetails.importmap;
|
|
214
|
+
|
|
215
|
+
if (typeof importmap === 'string') {
|
|
216
|
+
const notFound = {};
|
|
217
|
+
const content = await readJson(dir, importmap, notFound);
|
|
218
|
+
|
|
219
|
+
if (content === notFound) {
|
|
220
|
+
fail('importMapFileNotFound_0028', dir, importmap);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const baseDir = dirname(resolve(dir, importmap));
|
|
224
|
+
return await resolveImportmap(baseDir, content);
|
|
225
|
+
} else if (typeof importmap === 'undefined' && inherited) {
|
|
226
|
+
// Fall back to sharedDependencies or pilets.external if available
|
|
227
|
+
const shared: Array<string> = packageDetails.sharedDependencies ?? packageDetails.pilets?.externals;
|
|
228
|
+
|
|
229
|
+
if (Array.isArray(shared)) {
|
|
230
|
+
return shared.map((dep) => ({
|
|
231
|
+
id: dep,
|
|
232
|
+
name: dep,
|
|
233
|
+
entry: dep,
|
|
234
|
+
type: 'local',
|
|
235
|
+
ref: undefined,
|
|
236
|
+
requireId: dep,
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return await resolveImportmap(dir, importmap);
|
|
242
|
+
}
|
package/src/common/index.ts
CHANGED
|
@@ -10,8 +10,11 @@ export * from './emoji';
|
|
|
10
10
|
export * from './envs';
|
|
11
11
|
export * from './hash';
|
|
12
12
|
export * from './http';
|
|
13
|
+
export * from './importmap';
|
|
13
14
|
export * from './info';
|
|
14
15
|
export * from './injectors';
|
|
16
|
+
export * from './inspect';
|
|
17
|
+
export * from './interactive';
|
|
15
18
|
export * from './io';
|
|
16
19
|
export * from './language';
|
|
17
20
|
export * from './log';
|
|
@@ -19,10 +22,17 @@ export * from './merge';
|
|
|
19
22
|
export * from './npm';
|
|
20
23
|
export * from './pack';
|
|
21
24
|
export * from './package';
|
|
25
|
+
export * from './parallel';
|
|
22
26
|
export * from './patcher';
|
|
23
27
|
export * from './patches';
|
|
28
|
+
export * from './platform';
|
|
24
29
|
export * from './port';
|
|
25
30
|
export * from './rules';
|
|
26
31
|
export * from './scaffold';
|
|
27
32
|
export * from './scripts';
|
|
33
|
+
export * from './shell';
|
|
34
|
+
export * from './spec';
|
|
28
35
|
export * from './template';
|
|
36
|
+
export * from './url';
|
|
37
|
+
export * from './version';
|
|
38
|
+
export * from './watcher';
|
package/src/common/info.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { cpus, platform } from 'os';
|
|
2
|
+
|
|
1
3
|
const info = require('../../package.json');
|
|
4
|
+
const os = platform();
|
|
2
5
|
|
|
3
6
|
export function findCompatVersion(version: string) {
|
|
4
7
|
// we only care about major and minor
|
|
@@ -12,9 +15,14 @@ export function findCompatVersion(version: string) {
|
|
|
12
15
|
return major;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
export const nodeVersion = process.version.
|
|
18
|
+
export const nodeVersion = process.version.substring(1);
|
|
19
|
+
export const cliName = info.name;
|
|
16
20
|
export const cliVersion = info.version;
|
|
17
21
|
export const compatVersion = findCompatVersion(cliVersion);
|
|
18
22
|
export const repositoryUrl = info.repository.url;
|
|
19
23
|
export const isWindows = process.platform === 'win32';
|
|
20
24
|
export const pathSeparator = isWindows ? ';' : ':';
|
|
25
|
+
export const cpuCount = cpus().length;
|
|
26
|
+
export const standardHeaders = {
|
|
27
|
+
'user-agent': `piral-cli/http.node-${os}`,
|
|
28
|
+
};
|
package/src/common/injectors.ts
CHANGED
|
@@ -1,32 +1,59 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { KrasConfigurationInjectors } from 'kras';
|
|
1
|
+
import { resolve } from 'path';
|
|
3
2
|
import { liveIcon, settingsIcon } from './emoji';
|
|
4
3
|
import { logInfo, log, logReset } from './log';
|
|
5
|
-
import {
|
|
4
|
+
import { chalk } from '../external';
|
|
6
5
|
|
|
7
|
-
export function
|
|
8
|
-
return {
|
|
9
|
-
script: injectors.script || {
|
|
10
|
-
active: true,
|
|
11
|
-
},
|
|
12
|
-
har: injectors.har || {
|
|
13
|
-
active: true,
|
|
14
|
-
},
|
|
15
|
-
json: injectors.json || {
|
|
16
|
-
active: true,
|
|
17
|
-
},
|
|
18
|
-
[injectorName]: injectorConfig,
|
|
19
|
-
...injectors,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function notifyServerOnline(bundlers: Array<Bundler>, api: string | false) {
|
|
6
|
+
export function notifyServerOnline(path: string, api: string | false) {
|
|
24
7
|
return (svc: any) => {
|
|
25
8
|
log('generalDebug_0003', `The kras server for debugging is online!`);
|
|
26
9
|
const address = `${svc.protocol}://localhost:${chalk.green(svc.port)}`;
|
|
27
|
-
logInfo(`${liveIcon} Running at ${chalk.bold(address)}`);
|
|
10
|
+
logInfo(`${liveIcon} Running at ${chalk.bold(address + path)}`);
|
|
28
11
|
logInfo(`${settingsIcon} Manage via ${chalk.bold(address + api)}`);
|
|
29
12
|
logReset();
|
|
30
|
-
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createInitialKrasConfig(
|
|
17
|
+
directory: string,
|
|
18
|
+
sources: Array<string> = [],
|
|
19
|
+
map: Record<string, string> = {},
|
|
20
|
+
feed: string | Array<string> = [],
|
|
21
|
+
) {
|
|
22
|
+
return {
|
|
23
|
+
api: '/manage-mock-server',
|
|
24
|
+
directory,
|
|
25
|
+
map: {
|
|
26
|
+
'/': '',
|
|
27
|
+
...map,
|
|
28
|
+
},
|
|
29
|
+
ssl: undefined,
|
|
30
|
+
sources,
|
|
31
|
+
injectorDirs: [resolve(__dirname, '../injectors')],
|
|
32
|
+
injectors: {
|
|
33
|
+
script: {
|
|
34
|
+
active: true,
|
|
35
|
+
},
|
|
36
|
+
har: {
|
|
37
|
+
active: true,
|
|
38
|
+
delay: false,
|
|
39
|
+
},
|
|
40
|
+
json: {
|
|
41
|
+
active: true,
|
|
42
|
+
randomize: true,
|
|
43
|
+
},
|
|
44
|
+
piral: {
|
|
45
|
+
active: true,
|
|
46
|
+
headers: {},
|
|
47
|
+
},
|
|
48
|
+
pilet: {
|
|
49
|
+
active: true,
|
|
50
|
+
meta: 'debug-meta.json',
|
|
51
|
+
headers: {},
|
|
52
|
+
feed,
|
|
53
|
+
},
|
|
54
|
+
proxy: {
|
|
55
|
+
active: true,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
31
58
|
};
|
|
32
59
|
}
|
package/src/common/inspect.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { dirname, basename } from 'path';
|
|
2
2
|
import { unpackGzTar } from './archive';
|
|
3
|
-
import {
|
|
3
|
+
import { jju } from '../external';
|
|
4
|
+
import { PiletPackageData, PackageData, PackageFiles } from '../types';
|
|
4
5
|
|
|
5
6
|
const packageRoot = 'package/';
|
|
6
7
|
|
|
@@ -8,22 +9,20 @@ function getPackageJson(files: PackageFiles): PackageData {
|
|
|
8
9
|
const fileName = `${packageRoot}package.json`;
|
|
9
10
|
const fileContent = files[fileName];
|
|
10
11
|
const content = fileContent.toString('utf8');
|
|
11
|
-
return
|
|
12
|
+
return jju.parse(content);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
`dist/${data.main}`,
|
|
18
|
-
`${data.main}/index.js`,
|
|
19
|
-
`dist/${data.main}/index.js`,
|
|
20
|
-
'index.js',
|
|
21
|
-
'dist/index.js',
|
|
22
|
-
];
|
|
23
|
-
return paths.map((filePath) => `${packageRoot}${filePath}`).filter((filePath) => !!files[filePath])[0];
|
|
15
|
+
export function getPossiblePiletMainPaths(data: PiletPackageData) {
|
|
16
|
+
const { main = 'index.js' } = data;
|
|
17
|
+
return [main, `dist/${main}`, `${main}/index.js`, `dist/${main}/index.js`, 'index.js', 'dist/index.js'];
|
|
24
18
|
}
|
|
25
19
|
|
|
26
|
-
export
|
|
20
|
+
export function getPiletMainPath(data: PiletPackageData, files: PackageFiles) {
|
|
21
|
+
const paths = getPossiblePiletMainPaths(data);
|
|
22
|
+
return paths.map((filePath) => `${packageRoot}${filePath}`).find((filePath) => !!files[filePath]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface InspectedPiletPackageData extends PiletPackageData {
|
|
27
26
|
root: string;
|
|
28
27
|
}
|
|
29
28
|
|
|
@@ -31,7 +30,7 @@ export function inspectPackage(stream: NodeJS.ReadableStream): Promise<PackageDa
|
|
|
31
30
|
return unpackGzTar(stream).then((files) => getPackageJson(files));
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
export function inspectPilet(stream: NodeJS.ReadableStream): Promise<
|
|
33
|
+
export function inspectPilet(stream: NodeJS.ReadableStream): Promise<InspectedPiletPackageData> {
|
|
35
34
|
return unpackGzTar(stream).then((files) => {
|
|
36
35
|
const data = getPackageJson(files);
|
|
37
36
|
const path = getPiletMainPath(data, files);
|
|
@@ -3,6 +3,12 @@ import { promptConfirm, promptSelect } from './interactive';
|
|
|
3
3
|
const answer = 'Yes, really';
|
|
4
4
|
|
|
5
5
|
jest.mock('../external', () => ({
|
|
6
|
+
rc(_, cfg) {
|
|
7
|
+
return cfg;
|
|
8
|
+
},
|
|
9
|
+
ora() {
|
|
10
|
+
return {};
|
|
11
|
+
},
|
|
6
12
|
inquirer: {
|
|
7
13
|
prompt: (...any) => {
|
|
8
14
|
return Promise.resolve({ q: answer });
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Agent } from 'https';
|
|
2
|
+
import { openBrowserAt } from './browser';
|
|
3
|
+
import { standardHeaders } from './info';
|
|
4
|
+
import { logSuspend, logInfo } from './log';
|
|
5
|
+
import { axios, inquirer } from '../external';
|
|
6
|
+
import { PiletPublishScheme } from '../types';
|
|
2
7
|
|
|
3
8
|
export function promptSelect(message: string, values: Array<string>, defaultValue: string): Promise<string> {
|
|
4
9
|
const questions = [
|
|
@@ -24,3 +29,66 @@ export function promptConfirm(message: string, defaultValue: boolean): Promise<b
|
|
|
24
29
|
];
|
|
25
30
|
return inquirer.prompt(questions).then((answers: any) => answers.q);
|
|
26
31
|
}
|
|
32
|
+
|
|
33
|
+
type TokenResult = Promise<{ mode: PiletPublishScheme; token: string }>;
|
|
34
|
+
|
|
35
|
+
const tokenRetrievers: Record<string, TokenResult> = {};
|
|
36
|
+
|
|
37
|
+
export function getTokenInteractively(url: string, httpsAgent: Agent): TokenResult {
|
|
38
|
+
if (!(url in tokenRetrievers)) {
|
|
39
|
+
const logResume = logSuspend();
|
|
40
|
+
|
|
41
|
+
tokenRetrievers[url] = axios.default
|
|
42
|
+
.post(
|
|
43
|
+
url,
|
|
44
|
+
{
|
|
45
|
+
clientId: 'piral-cli',
|
|
46
|
+
clientName: 'Piral CLI',
|
|
47
|
+
description: 'Authorize the Piral CLI temporarily to perform actions in your name.',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
headers: {
|
|
51
|
+
...standardHeaders,
|
|
52
|
+
'content-type': 'application/json',
|
|
53
|
+
},
|
|
54
|
+
httpsAgent,
|
|
55
|
+
},
|
|
56
|
+
)
|
|
57
|
+
.then(async (res) => {
|
|
58
|
+
const { loginUrl, callbackUrl, expires } = res.data;
|
|
59
|
+
const now = new Date();
|
|
60
|
+
const then = new Date(expires);
|
|
61
|
+
const diff = ~~((then.valueOf() - now.valueOf()) / (60 * 1000));
|
|
62
|
+
|
|
63
|
+
logInfo(`Use the URL below to complete the login. The link expires in ${diff} minutes (${then}).`);
|
|
64
|
+
logInfo('===');
|
|
65
|
+
logInfo(loginUrl);
|
|
66
|
+
logInfo('===');
|
|
67
|
+
|
|
68
|
+
openBrowserAt(loginUrl);
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
while (true) {
|
|
72
|
+
const { data, status } = await axios.default.get(callbackUrl);
|
|
73
|
+
|
|
74
|
+
if (status === 202) {
|
|
75
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (status === 200) {
|
|
80
|
+
return { ...data };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
throw new Error(`Could not get status from interactive login endpoint.`);
|
|
84
|
+
}
|
|
85
|
+
} catch (ex) {
|
|
86
|
+
throw ex;
|
|
87
|
+
} finally {
|
|
88
|
+
logResume();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return tokenRetrievers[url];
|
|
94
|
+
}
|