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
package/src/common/package.ts
CHANGED
|
@@ -2,15 +2,86 @@ import { resolve, join, extname, basename, dirname, relative } from 'path';
|
|
|
2
2
|
import { log, fail } from './log';
|
|
3
3
|
import { cliVersion } from './info';
|
|
4
4
|
import { unpackTarball } from './archive';
|
|
5
|
-
import {
|
|
6
|
-
import { SourceLanguage, ForceOverwrite } from './enums';
|
|
5
|
+
import { ForceOverwrite } from './enums';
|
|
7
6
|
import { checkAppShellCompatibility } from './compatibility';
|
|
8
|
-
import { filesTar, filesOnceTar, declarationEntryExtensions } from './constants';
|
|
9
|
-
import { getHash, checkIsDirectory, matchFiles, getFileNames } from './io';
|
|
10
|
-
import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
|
|
11
|
-
import { Framework, FileInfo, PiletsInfo, TemplateFileLocation } from '../types';
|
|
12
|
-
import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath, makeExternals } from './npm';
|
|
13
7
|
import { deepMerge } from './merge';
|
|
8
|
+
import { onlyUnique } from './utils';
|
|
9
|
+
import { readImportmap } from './importmap';
|
|
10
|
+
import { getHash, checkIsDirectory, matchFiles } from './io';
|
|
11
|
+
import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
|
|
12
|
+
import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath, tryResolvePackage, isNpmPackage } from './npm';
|
|
13
|
+
import { makePiletExternals, makeExternals, findPackageRoot, findSpecificVersion, makeNpmAlias } from './npm';
|
|
14
|
+
import { getModulePath } from '../external';
|
|
15
|
+
import { getDependencies, getDependencyPackages, getDevDependencies } from './language';
|
|
16
|
+
import { getDevDependencyPackages, getFrameworkDependencies } from './language';
|
|
17
|
+
import {
|
|
18
|
+
declarationEntryExtensions,
|
|
19
|
+
piralJsonSchemaUrl,
|
|
20
|
+
piletJsonSchemaUrl,
|
|
21
|
+
filesTar,
|
|
22
|
+
filesOnceTar,
|
|
23
|
+
bundlerNames,
|
|
24
|
+
frameworkLibs,
|
|
25
|
+
piralJson,
|
|
26
|
+
piletJson,
|
|
27
|
+
packageJson,
|
|
28
|
+
} from './constants';
|
|
29
|
+
import {
|
|
30
|
+
SourceLanguage,
|
|
31
|
+
Framework,
|
|
32
|
+
FileInfo,
|
|
33
|
+
PiletsInfo,
|
|
34
|
+
TemplateFileLocation,
|
|
35
|
+
PiletPackageData,
|
|
36
|
+
PiralPackageData,
|
|
37
|
+
SharedDependency,
|
|
38
|
+
PiletDefinition,
|
|
39
|
+
AppDefinition,
|
|
40
|
+
PiralInstancePackageData,
|
|
41
|
+
} from '../types';
|
|
42
|
+
|
|
43
|
+
export interface PiralInstanceData {
|
|
44
|
+
packageName: Framework;
|
|
45
|
+
language: SourceLanguage;
|
|
46
|
+
reactVersion: number;
|
|
47
|
+
reactRouterVersion: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function appendBundler(devDependencies: Record<string, string>, bundler: string, proposedVersion: string) {
|
|
51
|
+
if (bundler && bundler !== 'none') {
|
|
52
|
+
if (isValidDependency(bundler)) {
|
|
53
|
+
const sep = bundler.indexOf('@', 1);
|
|
54
|
+
const hasVersion = sep !== -1;
|
|
55
|
+
const proposedName = bundler.substring(0, hasVersion ? sep : bundler.length);
|
|
56
|
+
const givenVersion = hasVersion ? bundler.substring(sep + 1) : proposedVersion;
|
|
57
|
+
const name = bundlerNames.includes(proposedName as any) ? `piral-cli-${bundler}` : proposedName;
|
|
58
|
+
const versions = new Set([
|
|
59
|
+
givenVersion,
|
|
60
|
+
givenVersion.includes('-beta.') && 'next',
|
|
61
|
+
givenVersion.includes('-alpha.') && 'canary',
|
|
62
|
+
givenVersion.includes('.') && givenVersion.split('.').slice(0, 2).join('.'),
|
|
63
|
+
'latest',
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
for (const version of versions) {
|
|
67
|
+
if (version) {
|
|
68
|
+
const isAvailable = await findSpecificVersion(name, version);
|
|
69
|
+
|
|
70
|
+
// only if something was returned we know that the version exists; so we can take it.
|
|
71
|
+
if (isAvailable) {
|
|
72
|
+
devDependencies[name] = version;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
log('generalWarning_0001', `Could not find a valid version for the provided bundler "${bundler}".'`);
|
|
79
|
+
} else {
|
|
80
|
+
//Error case - print warning and ignore
|
|
81
|
+
log('generalWarning_0001', `The provided bundler name "${bundler}" does not refer to a valid package name.'`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
14
85
|
|
|
15
86
|
function getDependencyVersion(
|
|
16
87
|
name: string,
|
|
@@ -86,101 +157,157 @@ async function getMatchingFiles(
|
|
|
86
157
|
}
|
|
87
158
|
|
|
88
159
|
export function getPiralPath(root: string, name: string) {
|
|
89
|
-
const path =
|
|
90
|
-
|
|
91
|
-
|
|
160
|
+
const path = findPackageRoot(name, root);
|
|
161
|
+
|
|
162
|
+
if (!path) {
|
|
163
|
+
fail('invalidPiralReference_0043');
|
|
164
|
+
}
|
|
165
|
+
|
|
92
166
|
return dirname(path);
|
|
93
167
|
}
|
|
94
168
|
|
|
95
|
-
export function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
169
|
+
export async function findPiralInstance(
|
|
170
|
+
proposedApp: string,
|
|
171
|
+
baseDir: string,
|
|
172
|
+
port: number,
|
|
173
|
+
): Promise<PiralInstancePackageData> {
|
|
174
|
+
const path = findPackageRoot(proposedApp, baseDir);
|
|
175
|
+
|
|
176
|
+
if (path) {
|
|
177
|
+
log('generalDebug_0003', `Following the app package in "${path}" ...`);
|
|
178
|
+
const root = dirname(path);
|
|
179
|
+
const appPackage = await readJson(root, basename(path));
|
|
180
|
+
const relPath = appPackage && appPackage.app;
|
|
181
|
+
appPackage.app = relPath && resolve(root, relPath);
|
|
182
|
+
appPackage.root = root;
|
|
183
|
+
appPackage.port = port;
|
|
184
|
+
return appPackage;
|
|
103
185
|
}
|
|
104
|
-
}
|
|
105
186
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
for (const item of pck) {
|
|
109
|
-
const result = findPackage(item, baseDir);
|
|
187
|
+
fail('appInstanceNotFound_0010', proposedApp);
|
|
188
|
+
}
|
|
110
189
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
190
|
+
export async function findPiralInstances(
|
|
191
|
+
proposedApps: Array<string>,
|
|
192
|
+
piletPackage: PiletPackageData,
|
|
193
|
+
piletDefinition: undefined | PiletDefinition,
|
|
194
|
+
baseDir: string,
|
|
195
|
+
) {
|
|
196
|
+
if (proposedApps) {
|
|
197
|
+
// do nothing
|
|
198
|
+
} else if (piletDefinition) {
|
|
199
|
+
const availableApps = Object.keys(piletDefinition.piralInstances || {});
|
|
200
|
+
proposedApps = availableApps.filter((m) => piletDefinition.piralInstances[m].selected);
|
|
201
|
+
|
|
202
|
+
if (proposedApps.length === 0) {
|
|
203
|
+
proposedApps = availableApps.slice(0, 1);
|
|
114
204
|
}
|
|
115
205
|
} else {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (path) {
|
|
119
|
-
log('generalDebug_0003', `Following the app package in "${path}" ...`);
|
|
120
|
-
const appPackage = require(path);
|
|
121
|
-
const relPath = appPackage && appPackage.app;
|
|
122
|
-
appPackage.app = relPath && resolve(dirname(path), relPath);
|
|
123
|
-
return appPackage;
|
|
124
|
-
}
|
|
206
|
+
proposedApps = [piletPackage.piral?.name].filter(Boolean);
|
|
125
207
|
}
|
|
126
208
|
|
|
127
|
-
|
|
209
|
+
if (proposedApps.length > 0) {
|
|
210
|
+
return Promise.all(
|
|
211
|
+
proposedApps.map((proposedApp) =>
|
|
212
|
+
findPiralInstance(proposedApp, baseDir, piletDefinition?.piralInstances?.[proposedApp]?.port ?? 0),
|
|
213
|
+
),
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return [];
|
|
128
218
|
}
|
|
129
219
|
|
|
130
|
-
export function readPiralPackage(root: string, name: string) {
|
|
220
|
+
export function readPiralPackage(root: string, name: string): Promise<PiralPackageData> {
|
|
131
221
|
log('generalDebug_0003', `Reading the piral package in "${root}" ...`);
|
|
132
222
|
const path = getPiralPath(root, name);
|
|
133
223
|
return readJson(path, 'package.json');
|
|
134
224
|
}
|
|
135
225
|
|
|
136
|
-
export function
|
|
226
|
+
export async function patchPiralPackage(
|
|
227
|
+
root: string,
|
|
137
228
|
app: string,
|
|
138
|
-
|
|
229
|
+
data: PiralInstanceData,
|
|
139
230
|
version: string,
|
|
140
|
-
framework: Framework,
|
|
141
231
|
bundler?: string,
|
|
142
232
|
) {
|
|
143
|
-
|
|
233
|
+
log('generalDebug_0003', `Patching the package.json in "${root}" ...`);
|
|
234
|
+
const pkg = await getPiralPackage(app, data, version, bundler);
|
|
235
|
+
|
|
236
|
+
await updateExistingJson(root, 'package.json', pkg);
|
|
237
|
+
log('generalDebug_0003', `Succesfully patched the package.json.`);
|
|
238
|
+
|
|
239
|
+
await updateExistingJson(root, piralJson, {
|
|
240
|
+
$schema: piralJsonSchemaUrl,
|
|
241
|
+
pilets: getPiletsInfo({}),
|
|
242
|
+
});
|
|
243
|
+
log('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export async function getPiralPackage(app: string, data: PiralInstanceData, version: string, bundler?: string) {
|
|
247
|
+
const framework = data.packageName;
|
|
144
248
|
const devDependencies = {
|
|
145
|
-
...getDevDependencies(
|
|
249
|
+
...getDevDependencies(
|
|
250
|
+
data.language,
|
|
251
|
+
getDevDependencyPackages(framework, data.reactVersion, data.reactRouterVersion),
|
|
252
|
+
),
|
|
146
253
|
'piral-cli': `${version}`,
|
|
147
254
|
};
|
|
255
|
+
const dependencies = {
|
|
256
|
+
...getFrameworkDependencies(framework, version),
|
|
257
|
+
...getDependencies(data.language, getDependencyPackages(framework, data.reactVersion, data.reactRouterVersion)),
|
|
258
|
+
};
|
|
148
259
|
|
|
149
|
-
|
|
150
|
-
devDependencies[`piral-cli-${bundler}`] = `${version}`;
|
|
151
|
-
}
|
|
260
|
+
await appendBundler(devDependencies, bundler, version);
|
|
152
261
|
|
|
153
262
|
return {
|
|
154
263
|
app,
|
|
155
264
|
scripts: {
|
|
156
265
|
start: 'piral debug',
|
|
157
266
|
build: 'piral build',
|
|
267
|
+
postinstall: 'piral declaration',
|
|
158
268
|
},
|
|
159
|
-
|
|
269
|
+
types: 'dist/index.d.ts',
|
|
270
|
+
importmap: {
|
|
271
|
+
imports: {},
|
|
272
|
+
inherit: [
|
|
273
|
+
'piral-base', // this we take in any case
|
|
274
|
+
framework !== 'piral-base' && 'piral-core', // this we take unless we selected piral-base, then obviously core is not invited to the party
|
|
275
|
+
framework === 'piral' && 'piral', // this we take only if we selected piral
|
|
276
|
+
].filter(Boolean),
|
|
277
|
+
},
|
|
278
|
+
dependencies,
|
|
160
279
|
devDependencies,
|
|
161
280
|
};
|
|
162
281
|
}
|
|
163
282
|
|
|
164
|
-
async function getAvailableFiles(
|
|
283
|
+
async function getAvailableFiles(
|
|
284
|
+
root: string,
|
|
285
|
+
name: string,
|
|
286
|
+
dirName: string,
|
|
287
|
+
fileMap: Array<TemplateFileLocation>,
|
|
288
|
+
): Promise<Array<FileDescriptor>> {
|
|
165
289
|
const source = getPiralPath(root, name);
|
|
166
|
-
|
|
167
|
-
|
|
290
|
+
const tgz = `${dirName}.tar`;
|
|
291
|
+
log('generalDebug_0003', `Checking if "${tgz}" exists in "${source}" ...`);
|
|
292
|
+
const exists = await checkExists(resolve(source, tgz));
|
|
168
293
|
|
|
169
294
|
if (exists) {
|
|
170
|
-
await unpackTarball(source,
|
|
295
|
+
await unpackTarball(source, tgz);
|
|
171
296
|
}
|
|
172
297
|
|
|
173
298
|
log('generalDebug_0003', `Get matching files from "${source}".`);
|
|
174
|
-
const base = resolve(source,
|
|
299
|
+
const base = resolve(source, dirName);
|
|
175
300
|
const files = await matchFiles(base, '**/*');
|
|
301
|
+
|
|
176
302
|
return files.map((file) => ({
|
|
177
303
|
sourcePath: file,
|
|
178
304
|
targetPath: resolve(root, relative(base, file)),
|
|
179
305
|
}));
|
|
180
306
|
}
|
|
181
307
|
|
|
182
|
-
export async function getFileStats(root: string, name: string) {
|
|
183
|
-
const files = await getAvailableFiles(root, name, filesTar);
|
|
308
|
+
export async function getFileStats(root: string, name: string, fileMap: Array<TemplateFileLocation> = []) {
|
|
309
|
+
const files = await getAvailableFiles(root, name, filesTar, fileMap);
|
|
310
|
+
|
|
184
311
|
return await Promise.all(
|
|
185
312
|
files.map(async (file) => {
|
|
186
313
|
const { sourcePath, targetPath } = file;
|
|
@@ -201,6 +328,7 @@ async function copyFiles(
|
|
|
201
328
|
subfiles: Array<FileDescriptor>,
|
|
202
329
|
forceOverwrite: ForceOverwrite,
|
|
203
330
|
originalFiles: Array<FileInfo>,
|
|
331
|
+
variables?: Record<string, string>,
|
|
204
332
|
) {
|
|
205
333
|
for (const subfile of subfiles) {
|
|
206
334
|
const { sourcePath, targetPath } = subfile;
|
|
@@ -221,6 +349,7 @@ export async function copyScaffoldingFiles(
|
|
|
221
349
|
target: string,
|
|
222
350
|
files: Array<string | TemplateFileLocation>,
|
|
223
351
|
piralInfo?: any,
|
|
352
|
+
variables?: Record<string, string>,
|
|
224
353
|
) {
|
|
225
354
|
log('generalDebug_0003', `Copying the scaffolding files ...`);
|
|
226
355
|
const allFiles: Array<FileDescriptor> = [];
|
|
@@ -234,7 +363,7 @@ export async function copyScaffoldingFiles(
|
|
|
234
363
|
await extendPackageOverridesFromTemplateFragment(target, piralInfo, allFiles);
|
|
235
364
|
}
|
|
236
365
|
|
|
237
|
-
await copyFiles(allFiles, ForceOverwrite.yes, []);
|
|
366
|
+
await copyFiles(allFiles, ForceOverwrite.yes, [], variables);
|
|
238
367
|
}
|
|
239
368
|
|
|
240
369
|
async function extendPackageOverridesFromTemplateFragment(root: string, piralInfo: any, files: Array<FileDescriptor>) {
|
|
@@ -263,31 +392,47 @@ async function extendPackageOverridesFromTemplateFragment(root: string, piralInf
|
|
|
263
392
|
}
|
|
264
393
|
}
|
|
265
394
|
|
|
395
|
+
function isTemplateFileLocation(item: string | TemplateFileLocation): item is TemplateFileLocation {
|
|
396
|
+
return typeof item === 'object';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function tryFindPackageVersion(packageName: string): string {
|
|
400
|
+
try {
|
|
401
|
+
const { version } = require(`${packageName}/package.json`);
|
|
402
|
+
return version;
|
|
403
|
+
} catch {
|
|
404
|
+
return undefined;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
266
408
|
export async function copyPiralFiles(
|
|
267
409
|
root: string,
|
|
268
410
|
name: string,
|
|
269
|
-
piralInfo:
|
|
411
|
+
piralInfo: PiralPackageData,
|
|
270
412
|
forceOverwrite: ForceOverwrite,
|
|
413
|
+
variables: Record<string, string>,
|
|
271
414
|
originalFiles?: Array<FileInfo>,
|
|
272
415
|
) {
|
|
273
416
|
log('generalDebug_0003', `Copying the Piral files ...`);
|
|
274
|
-
const files =
|
|
417
|
+
const { files: _files } = getPiletsInfo(piralInfo);
|
|
418
|
+
const fileMap = _files.filter(isTemplateFileLocation);
|
|
419
|
+
const files = await getAvailableFiles(root, name, filesTar, fileMap);
|
|
275
420
|
|
|
276
421
|
if (originalFiles === undefined) {
|
|
277
|
-
const initialFiles = await getAvailableFiles(root, name, filesOnceTar);
|
|
422
|
+
const initialFiles = await getAvailableFiles(root, name, filesOnceTar, fileMap);
|
|
278
423
|
files.push(...initialFiles);
|
|
279
424
|
originalFiles = [];
|
|
280
425
|
}
|
|
281
426
|
|
|
282
427
|
await extendPackageOverridesFromTemplateFragment(root, piralInfo, files);
|
|
283
|
-
await copyFiles(files, forceOverwrite, originalFiles);
|
|
428
|
+
await copyFiles(files, forceOverwrite, originalFiles, variables);
|
|
284
429
|
}
|
|
285
430
|
|
|
286
|
-
export function getPiletsInfo(piralInfo:
|
|
431
|
+
export function getPiletsInfo(piralInfo: Partial<PiralPackageData>): PiletsInfo {
|
|
287
432
|
const {
|
|
288
433
|
files = [],
|
|
289
|
-
externals = [],
|
|
290
434
|
scripts = {},
|
|
435
|
+
template = 'default',
|
|
291
436
|
validators = {},
|
|
292
437
|
devDependencies = {},
|
|
293
438
|
preScaffold = '',
|
|
@@ -299,8 +444,8 @@ export function getPiletsInfo(piralInfo: any): PiletsInfo {
|
|
|
299
444
|
|
|
300
445
|
return {
|
|
301
446
|
files,
|
|
302
|
-
externals,
|
|
303
447
|
scripts,
|
|
448
|
+
template,
|
|
304
449
|
validators,
|
|
305
450
|
devDependencies,
|
|
306
451
|
preScaffold,
|
|
@@ -350,37 +495,88 @@ function checkArrayOrUndefined(obj: Record<string, any>, key: string) {
|
|
|
350
495
|
return undefined;
|
|
351
496
|
}
|
|
352
497
|
|
|
353
|
-
export function findDependencyVersion(
|
|
498
|
+
export async function findDependencyVersion(
|
|
354
499
|
pckg: Record<string, any>,
|
|
355
500
|
rootPath: string,
|
|
356
|
-
|
|
501
|
+
dependency: SharedDependency,
|
|
357
502
|
): Promise<string> {
|
|
358
503
|
const { devDependencies = {}, dependencies = {} } = pckg;
|
|
504
|
+
const packageName = dependency.name;
|
|
359
505
|
const desiredVersion = dependencies[packageName] ?? devDependencies[packageName];
|
|
506
|
+
const [parent] = dependency.parents || [];
|
|
360
507
|
|
|
361
508
|
if (desiredVersion) {
|
|
362
|
-
if (
|
|
363
|
-
return
|
|
509
|
+
if (isNpmPackage(desiredVersion)) {
|
|
510
|
+
return desiredVersion;
|
|
511
|
+
} else if (isGitPackage(desiredVersion)) {
|
|
512
|
+
return makeGitUrl(desiredVersion);
|
|
364
513
|
} else if (isLocalPackage(rootPath, desiredVersion)) {
|
|
365
|
-
return
|
|
514
|
+
return makeFilePath(rootPath, desiredVersion);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (parent) {
|
|
519
|
+
// in case the dependency came from another package (= parent)
|
|
520
|
+
// we should start the lookup in its directory (pnpm issue)
|
|
521
|
+
const parentPath = tryResolvePackage(parent, rootPath);
|
|
522
|
+
|
|
523
|
+
if (parentPath) {
|
|
524
|
+
rootPath = dirname(parentPath);
|
|
366
525
|
}
|
|
367
526
|
}
|
|
368
527
|
|
|
369
|
-
|
|
528
|
+
const version = await findPackageVersion(rootPath, packageName);
|
|
529
|
+
|
|
530
|
+
if (dependency.alias) {
|
|
531
|
+
return makeNpmAlias(dependency.alias, version);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return version;
|
|
370
535
|
}
|
|
371
536
|
|
|
372
|
-
export async function findPackageVersion(rootPath: string, packageName: string): Promise<string> {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
537
|
+
export async function findPackageVersion(rootPath: string, packageName: string | Array<string>): Promise<string> {
|
|
538
|
+
const packages = Array.isArray(packageName) ? packageName : [packageName];
|
|
539
|
+
|
|
540
|
+
for (const pckg of packages) {
|
|
541
|
+
try {
|
|
542
|
+
log('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
|
|
543
|
+
const moduleName = getModulePath(rootPath, pckg);
|
|
544
|
+
const packageJson = await findFile(moduleName, 'package.json');
|
|
545
|
+
const root = dirname(packageJson);
|
|
546
|
+
const { version } = await readJson(root, 'package.json');
|
|
547
|
+
return version;
|
|
548
|
+
} catch {}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
log('cannotResolveDependency_0053', packages, rootPath);
|
|
552
|
+
return 'latest';
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export function flattenExternals(dependencies: Array<SharedDependency>) {
|
|
556
|
+
return dependencies.map((m) => m.name).filter(onlyUnique);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
export async function retrieveExternals(root: string, packageInfo: any): Promise<Array<SharedDependency>> {
|
|
560
|
+
const sharedDependencies = await readImportmap(root, packageInfo);
|
|
561
|
+
|
|
562
|
+
if (sharedDependencies.length === 0) {
|
|
563
|
+
const allDeps = {
|
|
564
|
+
...packageInfo.devDependencies,
|
|
565
|
+
...packageInfo.dependencies,
|
|
566
|
+
};
|
|
567
|
+
const deps = packageInfo.pilets?.externals;
|
|
568
|
+
const externals = await makeExternals(root, allDeps, deps);
|
|
569
|
+
return externals.map((ext) => ({
|
|
570
|
+
id: ext,
|
|
571
|
+
name: ext,
|
|
572
|
+
entry: ext,
|
|
573
|
+
type: 'local',
|
|
574
|
+
ref: undefined,
|
|
575
|
+
requireId: ext,
|
|
576
|
+
}));
|
|
383
577
|
}
|
|
578
|
+
|
|
579
|
+
return sharedDependencies;
|
|
384
580
|
}
|
|
385
581
|
|
|
386
582
|
export async function retrievePiletsInfo(entryFile: string) {
|
|
@@ -390,29 +586,51 @@ export async function retrievePiletsInfo(entryFile: string) {
|
|
|
390
586
|
fail('entryPointDoesNotExist_0073', entryFile);
|
|
391
587
|
}
|
|
392
588
|
|
|
393
|
-
const
|
|
589
|
+
const packageJsonPath = await findFile(entryFile, packageJson);
|
|
394
590
|
|
|
395
|
-
if (!
|
|
591
|
+
if (!packageJsonPath) {
|
|
396
592
|
fail('packageJsonMissing_0074');
|
|
397
593
|
}
|
|
398
594
|
|
|
399
|
-
const
|
|
595
|
+
const root = dirname(packageJsonPath);
|
|
596
|
+
const packageInfo = await readJson(root, packageJson);
|
|
597
|
+
const piralJsonPkg = await readJson(root, piralJson);
|
|
598
|
+
const pilets: PiletsInfo = {
|
|
599
|
+
...getPiletsInfo(packageInfo),
|
|
600
|
+
...piralJsonPkg.pilets,
|
|
601
|
+
};
|
|
602
|
+
const externals = await retrieveExternals(root, packageInfo);
|
|
603
|
+
const dependencies = {
|
|
604
|
+
std: packageInfo.dependencies || {},
|
|
605
|
+
dev: packageInfo.devDependencies || {},
|
|
606
|
+
peer: packageInfo.peerDependencies || {},
|
|
607
|
+
};
|
|
608
|
+
const framework = frameworkLibs.find((lib) => lib in dependencies.std || lib in dependencies.dev);
|
|
400
609
|
|
|
401
610
|
return {
|
|
402
|
-
...
|
|
611
|
+
...pilets,
|
|
612
|
+
externals,
|
|
403
613
|
name: packageInfo.name,
|
|
404
614
|
version: packageInfo.version,
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
dev: packageInfo.devDependencies || {},
|
|
408
|
-
peer: packageInfo.peerDependencies || {},
|
|
409
|
-
},
|
|
615
|
+
framework,
|
|
616
|
+
dependencies,
|
|
410
617
|
scripts: packageInfo.scripts,
|
|
411
618
|
ignored: checkArrayOrUndefined(packageInfo, 'preservedDependencies'),
|
|
412
|
-
root
|
|
619
|
+
root,
|
|
413
620
|
};
|
|
414
621
|
}
|
|
415
622
|
|
|
623
|
+
export function validateSharedDependencies(externals: Array<SharedDependency>) {
|
|
624
|
+
// See #591 - we should warn in case somebody shared piral packages
|
|
625
|
+
for (const external of externals) {
|
|
626
|
+
const name = external.name;
|
|
627
|
+
|
|
628
|
+
if (external.type === 'local' && name.startsWith('piral-') && name.indexOf('/') === -1) {
|
|
629
|
+
log('invalidSharedDependency_0029', name);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
416
634
|
export function isValidDependency(name: string) {
|
|
417
635
|
// super simple check at the moment
|
|
418
636
|
// just to filter out things like "redux-saga/effects" and "@scope/redux-saga/effects"
|
|
@@ -423,21 +641,41 @@ export async function patchPiletPackage(
|
|
|
423
641
|
root: string,
|
|
424
642
|
name: string,
|
|
425
643
|
version: string,
|
|
426
|
-
piralInfo:
|
|
644
|
+
piralInfo: PiralPackageData,
|
|
645
|
+
fromEmulator: boolean,
|
|
427
646
|
newInfo?: { language: SourceLanguage; bundler: string },
|
|
428
647
|
) {
|
|
429
648
|
log('generalDebug_0003', `Patching the package.json in "${root}" ...`);
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
649
|
+
const pkg = await getPiletPackage(root, name, version, piralInfo, fromEmulator, newInfo);
|
|
650
|
+
|
|
651
|
+
await updateExistingJson(root, packageJson, pkg);
|
|
652
|
+
log('generalDebug_0003', `Succesfully patched the package.json.`);
|
|
653
|
+
|
|
654
|
+
await updateExistingJson(root, piletJson, {
|
|
655
|
+
$schema: piletJsonSchemaUrl,
|
|
656
|
+
piralInstances: {
|
|
657
|
+
[name]: {},
|
|
658
|
+
},
|
|
659
|
+
});
|
|
660
|
+
log('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
async function getPiletPackage(
|
|
664
|
+
root: string,
|
|
665
|
+
name: string,
|
|
666
|
+
version: string,
|
|
667
|
+
piralInfo: PiralPackageData,
|
|
668
|
+
fromEmulator: boolean,
|
|
669
|
+
newInfo?: { language: SourceLanguage; bundler: string },
|
|
670
|
+
) {
|
|
671
|
+
const { piralCLI = { version: cliVersion } } = piralInfo;
|
|
672
|
+
const { packageOverrides, ...info } = getPiletsInfo(piralInfo);
|
|
435
673
|
const piralDependencies = {
|
|
436
674
|
...piralInfo.devDependencies,
|
|
437
675
|
...piralInfo.dependencies,
|
|
438
676
|
};
|
|
677
|
+
const toolVersion = piralCLI.version;
|
|
439
678
|
const typeDependencies = newInfo ? getDevDependencies(newInfo.language) : {};
|
|
440
|
-
const allExternals = makeExternals(externals);
|
|
441
679
|
const scripts = newInfo
|
|
442
680
|
? {
|
|
443
681
|
start: 'pilet debug',
|
|
@@ -446,21 +684,8 @@ export async function patchPiletPackage(
|
|
|
446
684
|
...info.scripts,
|
|
447
685
|
}
|
|
448
686
|
: info.scripts;
|
|
449
|
-
const
|
|
450
|
-
const
|
|
451
|
-
...allExternals.reduce((deps, name) => {
|
|
452
|
-
const valid = isValidDependency(name);
|
|
453
|
-
deps[name] = valid ? '*' : undefined;
|
|
454
|
-
|
|
455
|
-
if (!valid) {
|
|
456
|
-
peerModules.push(name);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
return deps;
|
|
460
|
-
}, {}),
|
|
461
|
-
[name]: `*`,
|
|
462
|
-
};
|
|
463
|
-
const devDependencies = {
|
|
687
|
+
const allExternals = await makePiletExternals(root, piralDependencies, fromEmulator, piralInfo);
|
|
688
|
+
const devDependencies: Record<string, string> = {
|
|
464
689
|
...Object.keys(typeDependencies).reduce((deps, name) => {
|
|
465
690
|
deps[name] = piralDependencies[name] || typeDependencies[name];
|
|
466
691
|
return deps;
|
|
@@ -470,7 +695,7 @@ export async function patchPiletPackage(
|
|
|
470
695
|
return deps;
|
|
471
696
|
}, {}),
|
|
472
697
|
...allExternals.filter(isValidDependency).reduce((deps, name) => {
|
|
473
|
-
const version = piralDependencies[name];
|
|
698
|
+
const version = piralDependencies[name] || tryFindPackageVersion(name);
|
|
474
699
|
|
|
475
700
|
if (version || newInfo) {
|
|
476
701
|
// set only if we have an explicit version or we are in the scaffolding case
|
|
@@ -480,36 +705,30 @@ export async function patchPiletPackage(
|
|
|
480
705
|
return deps;
|
|
481
706
|
}, {}),
|
|
482
707
|
[name]: `${version || piralInfo.version}`,
|
|
708
|
+
['piral-cli']: toolVersion,
|
|
483
709
|
};
|
|
484
710
|
|
|
485
711
|
if (newInfo) {
|
|
486
|
-
|
|
487
|
-
devDependencies['piral-cli'] = `^${cliVersion}`;
|
|
488
|
-
|
|
489
|
-
if (bundler && bundler !== 'none') {
|
|
490
|
-
devDependencies[`piral-cli-${bundler}`] = `^${cliVersion}`;
|
|
491
|
-
}
|
|
712
|
+
await appendBundler(devDependencies, newInfo.bundler, toolVersion);
|
|
492
713
|
}
|
|
493
714
|
|
|
494
|
-
|
|
495
|
-
|
|
715
|
+
return deepMerge(packageOverrides, {
|
|
716
|
+
importmap: {
|
|
717
|
+
imports: {},
|
|
718
|
+
inherit: [name],
|
|
719
|
+
},
|
|
496
720
|
devDependencies,
|
|
497
|
-
peerDependencies,
|
|
498
|
-
peerModules,
|
|
499
721
|
dependencies: {
|
|
500
722
|
[name]: undefined,
|
|
501
723
|
},
|
|
502
724
|
scripts,
|
|
503
725
|
});
|
|
504
|
-
|
|
505
|
-
await updateExistingJson(root, 'package.json', packageContent);
|
|
506
|
-
log('generalDebug_0003', `Succesfully patched the package.json.`);
|
|
507
726
|
}
|
|
508
727
|
|
|
509
728
|
/**
|
|
510
729
|
* Returns true if its an emulator package, otherwise it has to be a "raw" app shell.
|
|
511
730
|
*/
|
|
512
|
-
export function checkAppShellPackage(appPackage:
|
|
731
|
+
export function checkAppShellPackage(appPackage: PiralPackageData) {
|
|
513
732
|
const { piralCLI = { generated: false, version: cliVersion } } = appPackage;
|
|
514
733
|
|
|
515
734
|
if (piralCLI.generated) {
|
|
@@ -521,26 +740,73 @@ export function checkAppShellPackage(appPackage: any) {
|
|
|
521
740
|
return false;
|
|
522
741
|
}
|
|
523
742
|
|
|
524
|
-
export
|
|
525
|
-
|
|
743
|
+
export function combinePiletExternals(
|
|
744
|
+
appShells: Array<string>,
|
|
745
|
+
peerDependencies: Record<string, string>,
|
|
746
|
+
peerModules: Array<string>,
|
|
747
|
+
importmap: Array<SharedDependency>,
|
|
748
|
+
) {
|
|
749
|
+
const externals = [...Object.keys(peerDependencies), ...peerModules];
|
|
750
|
+
|
|
751
|
+
for (let i = importmap.length; i--; ) {
|
|
752
|
+
const entry = importmap[i];
|
|
753
|
+
|
|
754
|
+
// if the entry has no parents, i.e., it was explicitly mentioned in the importmap
|
|
755
|
+
// then keep it in the importmap (=> prefer the distributed approach, which will always work)
|
|
756
|
+
if (Array.isArray(entry.parents)) {
|
|
757
|
+
// only accept entry as a centrally shared dependency if the entry appears in all
|
|
758
|
+
// mentioned / referenced app shells
|
|
759
|
+
// in other cases (e.g., if one app shell does not share this) use the distributed
|
|
760
|
+
// mechanism to ensure that the dependency can also be resolved in this shell
|
|
761
|
+
if (appShells.every((app) => entry.parents.includes(app))) {
|
|
762
|
+
externals.push(entry.name);
|
|
763
|
+
importmap.splice(i, 1);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
return externals;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export async function findPiletRoot(proposedRoot: string) {
|
|
772
|
+
const packageJson = await findFile(proposedRoot, 'package.json');
|
|
526
773
|
|
|
527
774
|
if (!packageJson) {
|
|
528
775
|
fail('packageJsonMissing_0075');
|
|
529
776
|
}
|
|
530
777
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
const appPackage = findPackage(
|
|
534
|
-
app || (piletPackage.piral && piletPackage.piral.name) || Object.keys(piletPackage.devDependencies),
|
|
535
|
-
target,
|
|
536
|
-
);
|
|
537
|
-
const appFile: string = appPackage && appPackage.app;
|
|
778
|
+
return dirname(packageJson);
|
|
779
|
+
}
|
|
538
780
|
|
|
539
|
-
|
|
540
|
-
|
|
781
|
+
export async function retrievePiletData(target: string, app?: string) {
|
|
782
|
+
const piletJsonPath = await findFile(target, piletJson);
|
|
783
|
+
const proposedRoot = piletJsonPath ? dirname(piletJsonPath) : target;
|
|
784
|
+
const root = await findPiletRoot(proposedRoot);
|
|
785
|
+
const piletPackage = await readJson(root, 'package.json');
|
|
786
|
+
const piletDefinition: PiletDefinition = piletJsonPath && (await readJson(proposedRoot, piletJson));
|
|
787
|
+
const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, target);
|
|
788
|
+
const apps: Array<AppDefinition> = [];
|
|
789
|
+
|
|
790
|
+
for (const appPackage of appPackages) {
|
|
791
|
+
const appFile: string = appPackage?.app;
|
|
792
|
+
const appRoot: string = appPackage?.root;
|
|
793
|
+
const appPort = appPackage?.port;
|
|
794
|
+
|
|
795
|
+
if (!appFile || !appRoot) {
|
|
796
|
+
fail('appInstanceInvalid_0011');
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
const emulator = checkAppShellPackage(appPackage);
|
|
800
|
+
apps.push({
|
|
801
|
+
appPackage,
|
|
802
|
+
appFile,
|
|
803
|
+
appRoot,
|
|
804
|
+
emulator,
|
|
805
|
+
appPort,
|
|
806
|
+
});
|
|
541
807
|
}
|
|
542
808
|
|
|
543
|
-
const
|
|
809
|
+
const importmap = await readImportmap(root, piletPackage);
|
|
544
810
|
|
|
545
811
|
return {
|
|
546
812
|
dependencies: piletPackage.dependencies || {},
|
|
@@ -548,37 +814,10 @@ export async function retrievePiletData(target: string, app?: string) {
|
|
|
548
814
|
peerDependencies: piletPackage.peerDependencies || {},
|
|
549
815
|
peerModules: piletPackage.peerModules || [],
|
|
550
816
|
ignored: checkArrayOrUndefined(piletPackage, 'preservedDependencies'),
|
|
551
|
-
|
|
817
|
+
schema: piletDefinition?.schemaVersion,
|
|
818
|
+
importmap,
|
|
819
|
+
apps,
|
|
552
820
|
piletPackage,
|
|
553
|
-
appPackage,
|
|
554
|
-
emulator,
|
|
555
821
|
root,
|
|
556
822
|
};
|
|
557
823
|
}
|
|
558
|
-
|
|
559
|
-
export async function findEntryModule(entryFile: string, target: string) {
|
|
560
|
-
const entry = basename(entryFile);
|
|
561
|
-
const files = await getFileNames(target);
|
|
562
|
-
const preferences = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.esm', '.es', '.es6', '.html'];
|
|
563
|
-
const results = [];
|
|
564
|
-
log('generalDebug_0003', `Found ${files.length} potential entry points in "${target}".`);
|
|
565
|
-
|
|
566
|
-
for (const file of files) {
|
|
567
|
-
const ext = extname(file);
|
|
568
|
-
const fullPath = join(target, file);
|
|
569
|
-
|
|
570
|
-
if (file === entry) {
|
|
571
|
-
return fullPath;
|
|
572
|
-
} else if (file.replace(ext, '') === entry) {
|
|
573
|
-
const prefIndex = preferences.indexOf(ext);
|
|
574
|
-
|
|
575
|
-
if (prefIndex !== -1) {
|
|
576
|
-
results[prefIndex] = fullPath;
|
|
577
|
-
} else {
|
|
578
|
-
results[preferences.length] = fullPath;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
return results.filter(Boolean).shift() || entryFile;
|
|
584
|
-
}
|