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
package/src/common/emulator.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { join, resolve, relative } from 'path';
|
|
2
|
-
import { findDependencyVersion, copyScaffoldingFiles, isValidDependency } from './package';
|
|
3
|
-
import {
|
|
4
|
-
import { filesTar, filesOnceTar } from './constants';
|
|
2
|
+
import { findDependencyVersion, copyScaffoldingFiles, isValidDependency, flattenExternals } from './package';
|
|
3
|
+
import { createPiralStubIndexIfNotExists } from './template';
|
|
4
|
+
import { filesTar, filesOnceTar, packageJson, piralJson } from './constants';
|
|
5
5
|
import { cliVersion } from './info';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { createNpmPackage } from './npm';
|
|
7
|
+
import { createPiralDeclaration } from './declaration';
|
|
8
8
|
import { ForceOverwrite } from './enums';
|
|
9
9
|
import { createTarball } from './archive';
|
|
10
|
-
import { LogLevels, TemplateFileLocation } from '../types';
|
|
10
|
+
import { LogLevels, SharedDependency, PiletsInfo, TemplateFileLocation } from '../types';
|
|
11
11
|
import {
|
|
12
12
|
createDirectory,
|
|
13
13
|
removeDirectory,
|
|
@@ -15,42 +15,59 @@ import {
|
|
|
15
15
|
updateExistingJson,
|
|
16
16
|
getFileNames,
|
|
17
17
|
removeAny,
|
|
18
|
+
readJson,
|
|
18
19
|
} from './io';
|
|
19
20
|
|
|
20
|
-
const packageJson = 'package.json';
|
|
21
|
-
|
|
22
21
|
export async function createEmulatorSources(
|
|
23
22
|
sourceDir: string,
|
|
23
|
+
externals: Array<SharedDependency>,
|
|
24
24
|
targetDir: string,
|
|
25
25
|
targetFile: string,
|
|
26
26
|
logLevel: LogLevels,
|
|
27
27
|
) {
|
|
28
|
-
const piralPkg =
|
|
29
|
-
const
|
|
30
|
-
const
|
|
28
|
+
const piralPkg = await readJson(sourceDir, packageJson);
|
|
29
|
+
const piralJsonPkg = await readJson(sourceDir, piralJson);
|
|
30
|
+
const pilets: PiletsInfo = {
|
|
31
|
+
...piralPkg.pilets,
|
|
32
|
+
...piralJsonPkg.pilets,
|
|
33
|
+
};
|
|
34
|
+
const files: Array<string | TemplateFileLocation> = pilets.files ?? [];
|
|
35
|
+
const allDeps = {
|
|
36
|
+
...piralPkg.devDependencies,
|
|
37
|
+
...piralPkg.dependencies,
|
|
38
|
+
};
|
|
31
39
|
|
|
32
40
|
const externalPackages = await Promise.all(
|
|
33
|
-
|
|
34
|
-
name
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
externals
|
|
42
|
+
.filter((ext) => ext.type === 'local' && isValidDependency(ext.name))
|
|
43
|
+
.map(async (external) => ({
|
|
44
|
+
name: external.name,
|
|
45
|
+
version: await findDependencyVersion(piralPkg, sourceDir, external),
|
|
46
|
+
})),
|
|
37
47
|
);
|
|
38
48
|
const externalDependencies = externalPackages.reduce((deps, dep) => {
|
|
39
49
|
deps[dep.name] = dep.version;
|
|
40
50
|
return deps;
|
|
41
51
|
}, {} as Record<string, string>);
|
|
42
52
|
|
|
53
|
+
const importmapEntries = externalPackages.reduce((deps, dep) => {
|
|
54
|
+
deps[dep.name] = dep.name;
|
|
55
|
+
return deps;
|
|
56
|
+
}, {} as Record<string, string>);
|
|
57
|
+
|
|
43
58
|
const rootDir = resolve(targetDir, '..');
|
|
44
59
|
const appDir = relative(rootDir, targetDir);
|
|
45
60
|
const filesDir = resolve(rootDir, filesTar);
|
|
46
61
|
const filesOnceDir = resolve(rootDir, filesOnceTar);
|
|
47
62
|
|
|
48
63
|
const filesMap = files
|
|
64
|
+
.filter((file) => file && (typeof file === 'string' || typeof file === 'object'))
|
|
49
65
|
.map((file) => (typeof file === 'string' ? { from: file, to: file } : file))
|
|
66
|
+
.filter((file) => typeof file.to === 'string' && typeof file.from === 'string')
|
|
50
67
|
.map((file) => ({
|
|
51
68
|
...file,
|
|
52
69
|
to: file.to.replace(/\\/g, '/'),
|
|
53
|
-
from: join('files', file.
|
|
70
|
+
from: join('files', file.to).replace(/\\/g, '/'),
|
|
54
71
|
}));
|
|
55
72
|
|
|
56
73
|
// do not modify an existing JSON
|
|
@@ -64,8 +81,11 @@ export async function createEmulatorSources(
|
|
|
64
81
|
license: piralPkg.license,
|
|
65
82
|
homepage: piralPkg.homepage,
|
|
66
83
|
keywords: piralPkg.keywords,
|
|
84
|
+
importmap: {
|
|
85
|
+
imports: importmapEntries,
|
|
86
|
+
},
|
|
67
87
|
pilets: {
|
|
68
|
-
...
|
|
88
|
+
...pilets,
|
|
69
89
|
files: filesMap,
|
|
70
90
|
},
|
|
71
91
|
piralCLI: {
|
|
@@ -77,10 +97,10 @@ export async function createEmulatorSources(
|
|
|
77
97
|
app: `./${appDir}/index.html`,
|
|
78
98
|
peerDependencies: {},
|
|
79
99
|
devDependencies: {
|
|
80
|
-
...
|
|
81
|
-
...piralPkg.dependencies,
|
|
100
|
+
...allDeps,
|
|
82
101
|
...externalDependencies,
|
|
83
102
|
},
|
|
103
|
+
sharedDependencies: flattenExternals(externals),
|
|
84
104
|
repository: piralPkg.repository,
|
|
85
105
|
bugs: piralPkg.bugs,
|
|
86
106
|
author: piralPkg.author,
|
|
@@ -110,15 +130,15 @@ export async function createEmulatorSources(
|
|
|
110
130
|
await copyScaffoldingFiles(sourceDir, rootDir, piralPkg.files ?? []);
|
|
111
131
|
|
|
112
132
|
// actually including this one hints that the app shell should have been included - which is forbidden
|
|
113
|
-
await
|
|
133
|
+
await createPiralStubIndexIfNotExists(targetDir, 'index.js', ForceOverwrite.yes, {
|
|
114
134
|
name: piralPkg.name,
|
|
115
135
|
outFile: targetFile,
|
|
116
136
|
});
|
|
117
137
|
|
|
118
138
|
// generate the associated index.d.ts
|
|
119
|
-
await
|
|
139
|
+
await createPiralDeclaration(sourceDir, piralPkg.app ?? `./src/index.html`, targetDir, ForceOverwrite.yes, logLevel);
|
|
120
140
|
|
|
121
|
-
// since things like .gitignore are not properly treated by
|
|
141
|
+
// since things like .gitignore are not properly treated by npm we pack the files (for standard and once only)
|
|
122
142
|
await Promise.all([
|
|
123
143
|
createTarball(filesDir, rootDir, `${filesTar}.tar`),
|
|
124
144
|
createTarball(filesOnceDir, rootDir, `${filesOnceTar}.tar`),
|
|
@@ -132,7 +152,7 @@ export async function createEmulatorSources(
|
|
|
132
152
|
|
|
133
153
|
export async function packageEmulator(rootDir: string) {
|
|
134
154
|
// finally package everything up
|
|
135
|
-
await
|
|
155
|
+
await createNpmPackage(rootDir);
|
|
136
156
|
|
|
137
157
|
// get all files
|
|
138
158
|
const names = await getFileNames(rootDir);
|
package/src/common/enums.ts
CHANGED
package/src/common/envs.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
2
3
|
import { log } from './log';
|
|
4
|
+
import { frameworkLibs } from './constants';
|
|
3
5
|
import { pathSeparator, cliVersion, compatVersion } from './info';
|
|
4
6
|
import { StandardEnvProps } from '../types';
|
|
5
7
|
|
|
@@ -10,7 +12,7 @@ function hasPath(path: string) {
|
|
|
10
12
|
|
|
11
13
|
export function setStandardEnvs(options: StandardEnvProps) {
|
|
12
14
|
log('generalDebug_0003', `Setting environment variables in "${options.root}" ...`);
|
|
13
|
-
const packageJson =
|
|
15
|
+
const packageJson = JSON.parse(readFileSync(join(options.root, 'package.json'), 'utf8'));
|
|
14
16
|
const binDir = join(options.root, 'node_modules', '.bin');
|
|
15
17
|
|
|
16
18
|
process.env.BUILD_TIME = new Date().toDateString();
|
|
@@ -36,14 +38,24 @@ export function setStandardEnvs(options: StandardEnvProps) {
|
|
|
36
38
|
delete process.env.DEBUG_PILET;
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
if (options.publicPath) {
|
|
42
|
+
process.env.PIRAL_PUBLIC_PATH = options.publicPath;
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
if (options.production) {
|
|
40
46
|
process.env.NODE_ENV = 'production';
|
|
41
47
|
} else if (!process.env.NODE_ENV) {
|
|
42
48
|
process.env.NODE_ENV = 'development';
|
|
43
49
|
}
|
|
44
50
|
|
|
45
|
-
if (options.
|
|
46
|
-
|
|
51
|
+
if (Array.isArray(options.piralInstances) && options.piralInstances.length) {
|
|
52
|
+
process.env.PIRAL_INSTANCE = options.piralInstances.join(',');
|
|
53
|
+
} else {
|
|
54
|
+
options.piralInstances = [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (Array.isArray(options.dependencies) && options.dependencies.length) {
|
|
58
|
+
const excludedDependencies = [...frameworkLibs, ...options.piralInstances];
|
|
47
59
|
const dependencies = options.dependencies.filter((m) => !excludedDependencies.includes(m));
|
|
48
60
|
process.env.SHARED_DEPENDENCIES = dependencies.join(',');
|
|
49
61
|
} else {
|
package/src/common/hash.ts
CHANGED
|
@@ -7,3 +7,8 @@ export function computeHash(content: string | Buffer = '') {
|
|
|
7
7
|
export function computeMd5(content: string | Buffer = '') {
|
|
8
8
|
return createHash('md5').update(content).digest('hex');
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
export function computeIntegrity(content: string) {
|
|
12
|
+
const sum = createHash('sha256').update(content).digest('base64');
|
|
13
|
+
return `sha256-${sum}`;
|
|
14
|
+
}
|
package/src/common/http.test.ts
CHANGED
|
@@ -7,71 +7,83 @@ let errorOther = false;
|
|
|
7
7
|
let errorResponse = false;
|
|
8
8
|
let errorResponse2 = false;
|
|
9
9
|
|
|
10
|
-
jest.mock('
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
jest.mock('../external', () => ({
|
|
11
|
+
rc(_, cfg) {
|
|
12
|
+
return cfg;
|
|
13
|
+
},
|
|
14
|
+
ora() {
|
|
15
|
+
return {
|
|
16
|
+
warn() {},
|
|
17
|
+
fail() {},
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
axios: {
|
|
21
|
+
default: {
|
|
22
|
+
post(url, _, options) {
|
|
23
|
+
const found = url === apiUrl;
|
|
24
|
+
const auth = options.headers.authorization === 'Basic 123';
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
26
|
+
if (errorRequest) {
|
|
27
|
+
return Promise.reject({
|
|
28
|
+
request: {},
|
|
29
|
+
});
|
|
30
|
+
} else if (errorOther) {
|
|
31
|
+
return Promise.reject({
|
|
32
|
+
message: 'error',
|
|
33
|
+
});
|
|
34
|
+
} else if (errorResponse) {
|
|
35
|
+
return Promise.reject({
|
|
36
|
+
response: {
|
|
37
|
+
status: 410,
|
|
38
|
+
statusText: 'Not Gone',
|
|
39
|
+
data: '{ "message": "This component is not available anymore." }',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
} else if (errorResponse2) {
|
|
43
|
+
return Promise.reject({
|
|
44
|
+
response: {
|
|
45
|
+
status: 410,
|
|
46
|
+
statusText: 'Not Gone',
|
|
47
|
+
data: { message: 'This component is not available anymore.' },
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
} else if (!found) {
|
|
51
|
+
return Promise.reject({
|
|
52
|
+
response: {
|
|
53
|
+
status: 404,
|
|
54
|
+
statusText: 'Not found',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
} else if (!auth) {
|
|
58
|
+
return Promise.reject({
|
|
59
|
+
response: {
|
|
60
|
+
status: 401,
|
|
61
|
+
statusText: 'Not authorized',
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
return Promise.resolve({
|
|
66
|
+
status: 200,
|
|
67
|
+
statusText: 'OK',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
get(url, options) {
|
|
72
|
+
if (errorOther) {
|
|
73
|
+
return Promise.reject({
|
|
74
|
+
message: 'error',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return Promise.resolve({ data: 'test' });
|
|
78
|
+
},
|
|
68
79
|
},
|
|
69
80
|
},
|
|
81
|
+
FormData: jest.requireActual('form-data'),
|
|
70
82
|
}));
|
|
71
83
|
|
|
72
84
|
describe('HTTP Module', () => {
|
|
73
85
|
it('postFile form posts a file successfully should be ok', async () => {
|
|
74
|
-
const result = await postFile(apiUrl, '123', Buffer.from('example'));
|
|
86
|
+
const result = await postFile(apiUrl, 'basic', '123', Buffer.from('example'));
|
|
75
87
|
expect(result).toEqual({
|
|
76
88
|
response: undefined,
|
|
77
89
|
status: 200,
|
|
@@ -80,7 +92,7 @@ describe('HTTP Module', () => {
|
|
|
80
92
|
});
|
|
81
93
|
|
|
82
94
|
it('postFile form fails to post file should be false', async () => {
|
|
83
|
-
const result = await postFile(apiUrl, '124', Buffer.from('example'));
|
|
95
|
+
const result = await postFile(apiUrl, 'basic', '124', Buffer.from('example'));
|
|
84
96
|
expect(result).toEqual({
|
|
85
97
|
response: '',
|
|
86
98
|
status: 401,
|
|
@@ -89,7 +101,7 @@ describe('HTTP Module', () => {
|
|
|
89
101
|
});
|
|
90
102
|
|
|
91
103
|
it('postFile form not found to post file should be false', async () => {
|
|
92
|
-
const result = await postFile('http://sample.com/', '', Buffer.from('example'));
|
|
104
|
+
const result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
|
|
93
105
|
expect(result).toEqual({
|
|
94
106
|
response: '',
|
|
95
107
|
status: 404,
|
|
@@ -99,7 +111,7 @@ describe('HTTP Module', () => {
|
|
|
99
111
|
|
|
100
112
|
it('postFile call results in error request', async () => {
|
|
101
113
|
errorRequest = true;
|
|
102
|
-
const result = await postFile('http://sample.com/', '', Buffer.from('example'));
|
|
114
|
+
const result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
|
|
103
115
|
expect(result).toEqual({
|
|
104
116
|
response: undefined,
|
|
105
117
|
status: 500,
|
|
@@ -110,7 +122,7 @@ describe('HTTP Module', () => {
|
|
|
110
122
|
|
|
111
123
|
it('postFile call results in error other', async () => {
|
|
112
124
|
errorOther = true;
|
|
113
|
-
const result = await postFile('http://sample.com/', '', Buffer.from('example'));
|
|
125
|
+
const result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
|
|
114
126
|
expect(result).toEqual({
|
|
115
127
|
response: undefined,
|
|
116
128
|
status: 500,
|
|
@@ -121,7 +133,7 @@ describe('HTTP Module', () => {
|
|
|
121
133
|
|
|
122
134
|
it('postFile call results in error response', async () => {
|
|
123
135
|
errorResponse = true;
|
|
124
|
-
let result = await postFile('http://sample.com/', '', Buffer.from('example'));
|
|
136
|
+
let result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
|
|
125
137
|
expect(result).toEqual({
|
|
126
138
|
response: 'This component is not available anymore.',
|
|
127
139
|
status: 410,
|
|
@@ -129,7 +141,7 @@ describe('HTTP Module', () => {
|
|
|
129
141
|
});
|
|
130
142
|
errorResponse = false;
|
|
131
143
|
errorResponse2 = true;
|
|
132
|
-
result = await postFile('http://sample.com/', '', Buffer.from('example'));
|
|
144
|
+
result = await postFile('http://sample.com/', 'basic', '', Buffer.from('example'));
|
|
133
145
|
expect(result).toEqual({
|
|
134
146
|
response: 'This component is not available anymore.',
|
|
135
147
|
status: 410,
|
package/src/common/http.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { Agent } from 'https';
|
|
3
3
|
import { Stream } from 'stream';
|
|
4
|
-
import {
|
|
4
|
+
import { tmpdir } from 'os';
|
|
5
5
|
import { createWriteStream } from 'fs';
|
|
6
6
|
import { log } from './log';
|
|
7
|
+
import { standardHeaders } from './info';
|
|
8
|
+
import { getTokenInteractively } from './interactive';
|
|
7
9
|
import { axios, FormData } from '../external';
|
|
8
|
-
|
|
9
|
-
const os = platform();
|
|
10
|
+
import { PiletPublishScheme } from '../types';
|
|
10
11
|
|
|
11
12
|
function getMessage(body: string | { message?: string }) {
|
|
12
13
|
if (typeof body === 'string') {
|
|
@@ -41,9 +42,7 @@ export function downloadFile(target: string, ca?: Buffer): Promise<Array<string>
|
|
|
41
42
|
return axios.default
|
|
42
43
|
.get<Stream>(target, {
|
|
43
44
|
responseType: 'stream',
|
|
44
|
-
headers:
|
|
45
|
-
'user-agent': `piral-cli/http.node-${os}`,
|
|
46
|
-
},
|
|
45
|
+
headers: standardHeaders,
|
|
47
46
|
httpsAgent,
|
|
48
47
|
})
|
|
49
48
|
.then((res) => {
|
|
@@ -58,47 +57,98 @@ export function downloadFile(target: string, ca?: Buffer): Promise<Array<string>
|
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
export interface
|
|
60
|
+
export interface PostFormResult {
|
|
62
61
|
status: number;
|
|
63
62
|
success: boolean;
|
|
64
63
|
response?: object;
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
export
|
|
66
|
+
export type FormDataObj = Record<string, string | number | boolean | [Buffer, string]>;
|
|
67
|
+
|
|
68
|
+
export function postForm(
|
|
68
69
|
target: string,
|
|
70
|
+
scheme: PiletPublishScheme,
|
|
69
71
|
key: string,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
formData: FormDataObj,
|
|
73
|
+
customHeaders: Record<string, string> = {},
|
|
72
74
|
ca?: Buffer,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
interactive = false,
|
|
76
|
+
): Promise<PostFormResult> {
|
|
75
77
|
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
78
|
+
const form = new FormData();
|
|
76
79
|
|
|
77
|
-
Object.keys(
|
|
80
|
+
Object.keys(formData).forEach((key) => {
|
|
81
|
+
const value = formData[key];
|
|
78
82
|
|
|
79
|
-
|
|
83
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
84
|
+
form.append(key, value);
|
|
85
|
+
} else if (Array.isArray(value)) {
|
|
86
|
+
form.append(key, value[0], value[1]);
|
|
87
|
+
} else {
|
|
88
|
+
// unknown value - skip for now
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const headers: Record<string, string> = {
|
|
93
|
+
...form.getHeaders(),
|
|
94
|
+
...standardHeaders,
|
|
95
|
+
...customHeaders,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (key) {
|
|
99
|
+
switch (scheme) {
|
|
100
|
+
case 'basic':
|
|
101
|
+
headers.authorization = `Basic ${key}`;
|
|
102
|
+
break;
|
|
103
|
+
case 'bearer':
|
|
104
|
+
headers.authorization = `Bearer ${key}`;
|
|
105
|
+
break;
|
|
106
|
+
case 'digest':
|
|
107
|
+
headers.authorization = `Digest ${key}`;
|
|
108
|
+
break;
|
|
109
|
+
case 'none':
|
|
110
|
+
default:
|
|
111
|
+
headers.authorization = key;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
80
115
|
|
|
81
116
|
return axios.default
|
|
82
117
|
.post(target, form, {
|
|
83
|
-
headers
|
|
84
|
-
...form.getHeaders(),
|
|
85
|
-
authorization: `Basic ${key}`,
|
|
86
|
-
'user-agent': `piral-cli/http.node-${os}`,
|
|
87
|
-
},
|
|
118
|
+
headers,
|
|
88
119
|
httpsAgent,
|
|
89
120
|
maxContentLength: Infinity,
|
|
121
|
+
maxBodyLength: Infinity,
|
|
90
122
|
})
|
|
91
123
|
.then(
|
|
92
|
-
(res) =>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
124
|
+
(res) => {
|
|
125
|
+
return {
|
|
126
|
+
status: res.status,
|
|
127
|
+
success: true,
|
|
128
|
+
response: res.data,
|
|
129
|
+
};
|
|
130
|
+
},
|
|
97
131
|
(error) => {
|
|
98
132
|
if (error.response) {
|
|
99
133
|
// The request was made and the server responded with a status code
|
|
100
134
|
// that falls out of the range of 2xx
|
|
101
135
|
const { data, statusText, status } = error.response;
|
|
136
|
+
|
|
137
|
+
if (interactive && 'interactiveAuth' in data) {
|
|
138
|
+
const { interactiveAuth } = data;
|
|
139
|
+
|
|
140
|
+
if (typeof interactiveAuth === 'string') {
|
|
141
|
+
log(
|
|
142
|
+
'generalDebug_0003',
|
|
143
|
+
`Received status "${status}" from HTTP - trying interactive log in to "${interactiveAuth}".`,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
|
|
147
|
+
postForm(target, mode, token, formData, customHeaders, ca, false),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
102
152
|
const message = getMessage(data) || '';
|
|
103
153
|
log('unsuccessfulHttpPost_0066', statusText, status, message);
|
|
104
154
|
return {
|
|
@@ -139,3 +189,17 @@ export function postFile(
|
|
|
139
189
|
},
|
|
140
190
|
);
|
|
141
191
|
}
|
|
192
|
+
|
|
193
|
+
export function postFile(
|
|
194
|
+
target: string,
|
|
195
|
+
scheme: PiletPublishScheme,
|
|
196
|
+
key: string,
|
|
197
|
+
file: Buffer,
|
|
198
|
+
customFields: Record<string, string> = {},
|
|
199
|
+
customHeaders: Record<string, string> = {},
|
|
200
|
+
ca?: Buffer,
|
|
201
|
+
interactive = false,
|
|
202
|
+
): Promise<PostFormResult> {
|
|
203
|
+
const data: FormDataObj = { ...customFields, file: [file, 'pilet.tgz'] };
|
|
204
|
+
return postForm(target, scheme, key, data, customHeaders, ca, interactive);
|
|
205
|
+
}
|