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/npm.ts
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
1
|
-
import { resolve, relative } from 'path';
|
|
2
|
-
import { createReadStream, existsSync
|
|
1
|
+
import { resolve, relative, dirname } from 'path';
|
|
2
|
+
import { createReadStream, existsSync } from 'fs';
|
|
3
3
|
import { log, fail } from './log';
|
|
4
|
+
import { clients, detectClients, isWrapperClient } from './clients';
|
|
4
5
|
import { config } from './config';
|
|
6
|
+
import { legacyCoreExternals, frameworkLibs, defaultRegistry, packageJson } from './constants';
|
|
5
7
|
import { inspectPackage } from './inspect';
|
|
6
|
-
import {
|
|
7
|
-
import { readJson, checkExists, findFile } from './io';
|
|
8
|
+
import { readJson, checkExists } from './io';
|
|
8
9
|
import { clientTypeKeys } from '../helpers';
|
|
10
|
+
import { getModulePath } from '../external';
|
|
9
11
|
import { PackageType, NpmClientType } from '../types';
|
|
10
12
|
|
|
11
13
|
const gitPrefix = 'git+';
|
|
12
14
|
const filePrefix = 'file:';
|
|
15
|
+
const npmPrefix = 'npm:';
|
|
16
|
+
const pathPrefixes = ['/', './', '../', '.\\', '..\\', '~/', '~\\', filePrefix];
|
|
13
17
|
|
|
14
18
|
function isProjectReference(name: string) {
|
|
15
|
-
const target = resolve(name,
|
|
19
|
+
const target = resolve(name, packageJson);
|
|
16
20
|
return checkExists(target);
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
});
|
|
23
|
+
function resolveAbsPath(basePath: string, fullName: string) {
|
|
24
|
+
const prefixed = fullName.startsWith(filePrefix);
|
|
25
|
+
const relPath = !prefixed ? fullName : fullName.replace(filePrefix, '');
|
|
26
|
+
return resolve(basePath, relPath);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
access(resolve(root, 'package-lock.json'), constants.F_OK, (noPackageLock) => {
|
|
30
|
-
res(!noPackageLock);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
29
|
+
async function detectMonorepoRoot(root: string): Promise<[] | [string, NpmClientType]> {
|
|
30
|
+
let previous = root;
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
do {
|
|
33
|
+
if (await checkExists(resolve(root, 'lerna.json'))) {
|
|
34
|
+
return [root, 'lerna'];
|
|
35
|
+
}
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
if (await checkExists(resolve(root, 'rush.json'))) {
|
|
38
|
+
return [root, 'rush'];
|
|
39
|
+
}
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
41
|
+
if (await checkExists(resolve(root, 'pnpm-workspace.yaml'))) {
|
|
42
|
+
return [root, 'pnpm'];
|
|
43
|
+
}
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
}
|
|
45
|
+
const pj = await readJson(root, packageJson);
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
if (Array.isArray(pj?.workspaces)) {
|
|
48
|
+
if (await checkExists(resolve(root, '.pnp.cjs'))) {
|
|
49
|
+
return [root, 'pnp'];
|
|
50
|
+
}
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
if (await checkExists(resolve(root, 'yarn.lock'))) {
|
|
53
|
+
return [root, 'yarn'];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return [root, 'npm'];
|
|
59
57
|
}
|
|
60
|
-
}
|
|
61
58
|
|
|
62
|
-
|
|
59
|
+
previous = root;
|
|
60
|
+
root = dirname(root);
|
|
61
|
+
} while (root !== previous);
|
|
62
|
+
|
|
63
|
+
return [];
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
/**
|
|
@@ -69,36 +70,45 @@ export async function getLernaNpmClient(root: string): Promise<NpmClientType> {
|
|
|
69
70
|
*/
|
|
70
71
|
export async function determineNpmClient(root: string, selected?: NpmClientType): Promise<NpmClientType> {
|
|
71
72
|
if (!selected || !clientTypeKeys.includes(selected)) {
|
|
72
|
-
log('generalDebug_0003', 'No
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
log('generalDebug_0003', 'No npm client selected. Checking for lock or config files ...');
|
|
74
|
+
|
|
75
|
+
const searchedClients = await detectClients(root);
|
|
76
|
+
const foundClients = searchedClients.filter((m) => m.result);
|
|
77
|
+
|
|
78
|
+
log(
|
|
79
|
+
'generalDebug_0003',
|
|
80
|
+
`Results of the lock file check: ${searchedClients.map((m) => `${m.client}=${m.result}`).join(', ')}`,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
if (foundClients.length > 1) {
|
|
84
|
+
const wrapperClient = foundClients.find((m) => isWrapperClient(m.client));
|
|
85
|
+
|
|
86
|
+
if (wrapperClient) {
|
|
87
|
+
const { client } = wrapperClient;
|
|
88
|
+
log('generalDebug_0003', `Found valid wrapper client via lock or config file: "${client}".`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
77
91
|
|
|
78
|
-
if (
|
|
79
|
-
const
|
|
92
|
+
if (foundClients.length > 0) {
|
|
93
|
+
const { client } = foundClients[0];
|
|
80
94
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
95
|
+
if (foundClients.length > 1) {
|
|
96
|
+
const clientStr = `"${foundClients.map((m) => m.client).join('", "')}"`;
|
|
97
|
+
log('generalWarning_0001', `Found multiple clients via their lock or config files: ${clientStr}.`);
|
|
84
98
|
}
|
|
85
|
-
|
|
86
|
-
log('generalDebug_0003', `Found valid
|
|
87
|
-
return
|
|
88
|
-
} else if (hasYarn) {
|
|
89
|
-
log('generalDebug_0003', `Found valid Yarn client via lockfile.`);
|
|
90
|
-
return 'yarn';
|
|
91
|
-
} else if (hasPnpm) {
|
|
92
|
-
log('generalDebug_0003', `Found valid Pnpm client via lockfile.`);
|
|
93
|
-
return 'pnpm';
|
|
99
|
+
|
|
100
|
+
log('generalDebug_0003', `Found valid direct client via lock or config file: "${client}".`);
|
|
101
|
+
return client;
|
|
94
102
|
}
|
|
95
103
|
|
|
104
|
+
const defaultClient = config.npmClient;
|
|
105
|
+
|
|
96
106
|
if (clientTypeKeys.includes(defaultClient)) {
|
|
97
|
-
log('generalDebug_0003', `
|
|
107
|
+
log('generalDebug_0003', `Using the default client: "${defaultClient}".`);
|
|
98
108
|
return defaultClient;
|
|
99
109
|
}
|
|
100
110
|
|
|
101
|
-
log('generalDebug_0003', 'Using the
|
|
111
|
+
log('generalDebug_0003', 'Using the fallback "npm" client.');
|
|
102
112
|
return 'npm';
|
|
103
113
|
}
|
|
104
114
|
|
|
@@ -106,70 +116,111 @@ export async function determineNpmClient(root: string, selected?: NpmClientType)
|
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
export async function isMonorepoPackageRef(refName: string, root: string): Promise<boolean> {
|
|
109
|
-
const
|
|
110
|
-
const details = await c.listPackage(refName, root);
|
|
111
|
-
return details?.dependencies?.[refName]?.extraneous ?? false;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export type MonorepoKind = 'none' | 'lerna' | 'yarn';
|
|
119
|
+
const [monorepoRoot, client] = await detectMonorepoRoot(root);
|
|
115
120
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (file !== undefined) {
|
|
120
|
-
return 'lerna';
|
|
121
|
+
if (monorepoRoot) {
|
|
122
|
+
const c = clients[client];
|
|
123
|
+
return await c.isProject(monorepoRoot, refName);
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (Array.isArray(packageJson?.workspaces)) {
|
|
126
|
-
return 'yarn';
|
|
127
|
-
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
export function installNpmDependencies(client: NpmClientType, target = '.'): Promise<string> {
|
|
130
|
+
const { installDependencies } = clients[client];
|
|
131
|
+
return installDependencies(target);
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
export function
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
export async function installNpmPackageFromOptionalRegistry(
|
|
135
|
+
packageRef: string,
|
|
136
|
+
target = '.',
|
|
137
|
+
registry: string,
|
|
138
|
+
): Promise<void> {
|
|
139
|
+
try {
|
|
140
|
+
await installNpmPackage('npm', packageRef, target, '--registry', registry);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
if (registry === defaultRegistry) {
|
|
143
|
+
throw e;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
await installNpmPackage('npm', packageRef, target, '--registry', defaultRegistry);
|
|
147
|
+
}
|
|
135
148
|
}
|
|
136
149
|
|
|
137
|
-
export function
|
|
138
|
-
|
|
139
|
-
|
|
150
|
+
export async function uninstallNpmPackage(
|
|
151
|
+
client: NpmClientType,
|
|
152
|
+
packageRef: string,
|
|
153
|
+
target = '.',
|
|
154
|
+
...flags: Array<string>
|
|
155
|
+
): Promise<string> {
|
|
156
|
+
try {
|
|
157
|
+
const { uninstallPackage } = clients[client];
|
|
158
|
+
return await uninstallPackage(packageRef, target, ...flags);
|
|
159
|
+
} catch (ex) {
|
|
160
|
+
log(
|
|
161
|
+
'generalError_0002',
|
|
162
|
+
`Could not uninstall the package "${packageRef}" using ${client}. Make sure ${client} is correctly installed and accessible: ${ex}`,
|
|
163
|
+
);
|
|
164
|
+
throw ex;
|
|
165
|
+
}
|
|
140
166
|
}
|
|
141
167
|
|
|
142
|
-
export function
|
|
168
|
+
export async function installNpmPackage(
|
|
143
169
|
client: NpmClientType,
|
|
144
170
|
packageRef: string,
|
|
145
171
|
target = '.',
|
|
146
172
|
...flags: Array<string>
|
|
147
173
|
): Promise<string> {
|
|
148
|
-
|
|
149
|
-
|
|
174
|
+
try {
|
|
175
|
+
const { installPackage } = clients[client];
|
|
176
|
+
return await installPackage(packageRef, target, ...flags);
|
|
177
|
+
} catch (ex) {
|
|
178
|
+
log(
|
|
179
|
+
'generalError_0002',
|
|
180
|
+
`Could not install the package "${packageRef}" using ${client}. Make sure ${client} is correctly installed and accessible: ${ex}`,
|
|
181
|
+
);
|
|
182
|
+
throw ex;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function initNpmProject(client: NpmClientType, projectName: string, target: string) {
|
|
187
|
+
const { initProject } = clients[client];
|
|
188
|
+
return initProject(projectName, target);
|
|
150
189
|
}
|
|
151
190
|
|
|
152
|
-
export function
|
|
153
|
-
|
|
154
|
-
|
|
191
|
+
export function publishNpmPackage(
|
|
192
|
+
target = '.',
|
|
193
|
+
file = '*.tgz',
|
|
194
|
+
flags: Array<string> = [],
|
|
195
|
+
interactive = false,
|
|
196
|
+
): Promise<string> {
|
|
197
|
+
const { publishPackage, loginUser } = clients.npm;
|
|
198
|
+
return publishPackage(target, file, ...flags).catch(err => {
|
|
199
|
+
if (!interactive) {
|
|
200
|
+
throw err;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return loginUser().then(() => publishNpmPackage(target, file, flags, false));
|
|
204
|
+
});
|
|
155
205
|
}
|
|
156
206
|
|
|
157
|
-
export function
|
|
158
|
-
const
|
|
159
|
-
return
|
|
207
|
+
export function createNpmPackage(target = '.'): Promise<string> {
|
|
208
|
+
const { createPackage } = clients.npm;
|
|
209
|
+
return createPackage(target);
|
|
160
210
|
}
|
|
161
211
|
|
|
162
|
-
export function
|
|
163
|
-
const
|
|
164
|
-
return
|
|
212
|
+
export function findNpmTarball(packageRef: string): Promise<string> {
|
|
213
|
+
const { findTarball } = clients.npm;
|
|
214
|
+
return findTarball(packageRef);
|
|
165
215
|
}
|
|
166
216
|
|
|
167
217
|
export function findSpecificVersion(packageName: string, version: string): Promise<string> {
|
|
168
|
-
const
|
|
169
|
-
return
|
|
218
|
+
const { findSpecificVersion } = clients.npm;
|
|
219
|
+
return findSpecificVersion(packageName, version);
|
|
170
220
|
}
|
|
171
221
|
|
|
172
222
|
export function findLatestVersion(packageName: string) {
|
|
223
|
+
const { findSpecificVersion } = clients.npm;
|
|
173
224
|
return findSpecificVersion(packageName, 'latest');
|
|
174
225
|
}
|
|
175
226
|
|
|
@@ -177,7 +228,7 @@ export function isLocalPackage(baseDir: string, fullName: string) {
|
|
|
177
228
|
log('generalDebug_0003', 'Checking if its a local package ...');
|
|
178
229
|
|
|
179
230
|
if (fullName) {
|
|
180
|
-
if (
|
|
231
|
+
if (pathPrefixes.some((prefix) => fullName.startsWith(prefix))) {
|
|
181
232
|
log('generalDebug_0003', 'Found a local package by name.');
|
|
182
233
|
return true;
|
|
183
234
|
} else if (fullName.endsWith('.tgz')) {
|
|
@@ -195,6 +246,25 @@ export function isLocalPackage(baseDir: string, fullName: string) {
|
|
|
195
246
|
return false;
|
|
196
247
|
}
|
|
197
248
|
|
|
249
|
+
export function isNpmPackage(fullName: string) {
|
|
250
|
+
log('generalDebug_0003', 'Checking if its an npm alias ...');
|
|
251
|
+
|
|
252
|
+
if (fullName) {
|
|
253
|
+
const npmed = fullName.startsWith(npmPrefix);
|
|
254
|
+
|
|
255
|
+
if (npmed && fullName.substring(npmPrefix.length + 1).indexOf('@') !== -1) {
|
|
256
|
+
log('generalDebug_0003', 'Found an npm package alias by name.');
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function makeNpmAlias(name: string, version: string) {
|
|
265
|
+
return `${npmPrefix}${name}@${version}`;
|
|
266
|
+
}
|
|
267
|
+
|
|
198
268
|
export function isGitPackage(fullName: string) {
|
|
199
269
|
log('generalDebug_0003', 'Checking if its a Git package ...');
|
|
200
270
|
|
|
@@ -216,9 +286,7 @@ export function makeGitUrl(fullName: string) {
|
|
|
216
286
|
}
|
|
217
287
|
|
|
218
288
|
export function makeFilePath(basePath: string, fullName: string) {
|
|
219
|
-
const
|
|
220
|
-
const relPath = !prefixed ? fullName : fullName.replace(filePrefix, '');
|
|
221
|
-
const absPath = resolve(basePath, relPath);
|
|
289
|
+
const absPath = resolveAbsPath(basePath, fullName);
|
|
222
290
|
return `${filePrefix}${absPath}`;
|
|
223
291
|
}
|
|
224
292
|
|
|
@@ -242,7 +310,7 @@ export async function dissectPackageName(
|
|
|
242
310
|
const gitUrl = makeGitUrl(fullName);
|
|
243
311
|
return [gitUrl, 'latest', false, 'git'];
|
|
244
312
|
} else if (isLocalPackage(baseDir, fullName)) {
|
|
245
|
-
const fullPath =
|
|
313
|
+
const fullPath = resolveAbsPath(baseDir, fullName);
|
|
246
314
|
const exists = await checkExists(fullPath);
|
|
247
315
|
|
|
248
316
|
if (!exists) {
|
|
@@ -261,7 +329,7 @@ export async function dissectPackageName(
|
|
|
261
329
|
const type = 'registry';
|
|
262
330
|
|
|
263
331
|
if (index !== -1) {
|
|
264
|
-
return [fullName.
|
|
332
|
+
return [fullName.substring(0, index), fullName.substring(index + 1), true, type];
|
|
265
333
|
}
|
|
266
334
|
|
|
267
335
|
return [fullName, 'latest', false, type];
|
|
@@ -321,12 +389,35 @@ export async function getCurrentPackageDetails(
|
|
|
321
389
|
return [combinePackageRef(sourceName, desired, 'registry'), desired];
|
|
322
390
|
}
|
|
323
391
|
|
|
324
|
-
|
|
392
|
+
function tryResolve(packageName: string, baseDir = process.cwd()) {
|
|
393
|
+
try {
|
|
394
|
+
return getModulePath(baseDir, packageName);
|
|
395
|
+
} catch {
|
|
396
|
+
return undefined;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export function tryResolvePackage(name: string, baseDir: string = undefined) {
|
|
401
|
+
const path = baseDir ? tryResolve(name, baseDir) : tryResolve(name);
|
|
402
|
+
const root = baseDir || process.cwd();
|
|
403
|
+
|
|
404
|
+
if (!path) {
|
|
405
|
+
log('generalDebug_0003', `Could not resolve the package "${name}" in "${root}".`);
|
|
406
|
+
} else {
|
|
407
|
+
log('generalVerbose_0004', `Resolved the package "${name}" (from "${root}") to be "${path}".`);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return path;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export function findPackageRoot(pck: string, baseDir: string) {
|
|
414
|
+
return tryResolvePackage(`${pck}/${packageJson}`, baseDir);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export function isLinkedPackage(name: string, type: PackageType, hadVersion: boolean, target: string) {
|
|
325
418
|
if (type === 'registry' && !hadVersion) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
return true;
|
|
329
|
-
} catch {}
|
|
419
|
+
const root = findPackageRoot(name, target);
|
|
420
|
+
return typeof root === 'string';
|
|
330
421
|
}
|
|
331
422
|
|
|
332
423
|
return false;
|
|
@@ -334,27 +425,34 @@ export function isLinkedPackage(name: string, type: PackageType, hadVersion: boo
|
|
|
334
425
|
|
|
335
426
|
export function combinePackageRef(name: string, version: string, type: PackageType) {
|
|
336
427
|
if (type === 'registry') {
|
|
337
|
-
|
|
428
|
+
const tag = version || 'latest';
|
|
429
|
+
return `${name}@${tag}`;
|
|
338
430
|
}
|
|
339
431
|
|
|
340
432
|
return name;
|
|
341
433
|
}
|
|
342
434
|
|
|
343
|
-
export async function getPackageName(root: string, name: string, type: PackageType) {
|
|
435
|
+
export async function getPackageName(root: string, name: string, type: PackageType): Promise<string> {
|
|
344
436
|
switch (type) {
|
|
345
437
|
case 'file':
|
|
346
|
-
const originalPackageJson = await readJson(name,
|
|
438
|
+
const originalPackageJson = await readJson(name, packageJson);
|
|
347
439
|
|
|
348
440
|
if (!originalPackageJson.name) {
|
|
349
441
|
const p = resolve(process.cwd(), name);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
442
|
+
|
|
443
|
+
try {
|
|
444
|
+
const s = createReadStream(p);
|
|
445
|
+
const i = await inspectPackage(s);
|
|
446
|
+
return i.name;
|
|
447
|
+
} catch (err) {
|
|
448
|
+
log('generalError_0002', `Could not open package tarball at "${p}": "${err}`);
|
|
449
|
+
return undefined;
|
|
450
|
+
}
|
|
353
451
|
}
|
|
354
452
|
|
|
355
453
|
return originalPackageJson.name;
|
|
356
454
|
case 'git':
|
|
357
|
-
const pj = await readJson(root,
|
|
455
|
+
const pj = await readJson(root, packageJson);
|
|
358
456
|
const dd = pj.devDependencies || {};
|
|
359
457
|
return Object.keys(dd).filter((dep) => dd[dep] === name)[0];
|
|
360
458
|
case 'registry':
|
|
@@ -388,13 +486,54 @@ export function getPackageVersion(
|
|
|
388
486
|
}
|
|
389
487
|
}
|
|
390
488
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
const
|
|
489
|
+
async function getExternalsFrom(root: string, packageName: string): Promise<Array<string> | undefined> {
|
|
490
|
+
try {
|
|
491
|
+
const target = getModulePath(root, `${packageName}/${packageJson}`);
|
|
492
|
+
const dir = dirname(target);
|
|
493
|
+
const { sharedDependencies } = await readJson(dir, packageJson);
|
|
494
|
+
return sharedDependencies;
|
|
495
|
+
} catch (err) {
|
|
496
|
+
log('generalError_0002', `Could not get externals from "${packageName}": "${err}`);
|
|
497
|
+
return undefined;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
async function getCoreExternals(root: string, dependencies: Record<string, string>): Promise<Array<string>> {
|
|
502
|
+
for (const frameworkLib of frameworkLibs) {
|
|
503
|
+
if (dependencies[frameworkLib]) {
|
|
504
|
+
const deps = await getExternalsFrom(root, frameworkLib);
|
|
505
|
+
|
|
506
|
+
if (deps) {
|
|
507
|
+
return deps;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
log('frameworkLibMissing_0078', frameworkLibs);
|
|
513
|
+
return [];
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export async function makePiletExternals(
|
|
517
|
+
root: string,
|
|
518
|
+
dependencies: Record<string, string>,
|
|
519
|
+
fromEmulator: boolean,
|
|
520
|
+
piralInfo: any,
|
|
521
|
+
): Promise<Array<string>> {
|
|
522
|
+
if (fromEmulator) {
|
|
523
|
+
const { sharedDependencies = legacyCoreExternals } = piralInfo;
|
|
524
|
+
return sharedDependencies;
|
|
525
|
+
} else {
|
|
526
|
+
return await getCoreExternals(root, dependencies);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function mergeExternals(customExternals?: Array<string>, coreExternals: Array<string> = []) {
|
|
531
|
+
if (customExternals && Array.isArray(customExternals)) {
|
|
532
|
+
const [include, exclude] = customExternals.reduce<[Array<string>, Array<string>]>(
|
|
394
533
|
(prev, curr) => {
|
|
395
534
|
if (typeof curr === 'string') {
|
|
396
535
|
if (curr.startsWith('!')) {
|
|
397
|
-
prev[1].push(curr.
|
|
536
|
+
prev[1].push(curr.substring(1));
|
|
398
537
|
} else {
|
|
399
538
|
prev[0].push(curr);
|
|
400
539
|
}
|
|
@@ -410,3 +549,8 @@ export function makeExternals(externals?: Array<string>) {
|
|
|
410
549
|
|
|
411
550
|
return coreExternals;
|
|
412
551
|
}
|
|
552
|
+
|
|
553
|
+
export async function makeExternals(root: string, dependencies: Record<string, string>, externals: Array<string>) {
|
|
554
|
+
const coreExternals = await getCoreExternals(root, dependencies);
|
|
555
|
+
return mergeExternals(externals, coreExternals);
|
|
556
|
+
}
|
package/src/common/pack.test.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { createPiletPackage } from './pack';
|
|
2
2
|
import { resolve } from 'path';
|
|
3
3
|
|
|
4
|
-
let json = {};
|
|
4
|
+
let json: any = {};
|
|
5
5
|
|
|
6
6
|
jest.mock('./io', () => ({
|
|
7
|
-
readJson: (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
readJson: jest.fn(() => json),
|
|
8
|
+
removeDirectory: jest.fn(() => Promise.resolve()),
|
|
9
|
+
makeTempDir: jest.fn(() => Promise.resolve('')),
|
|
10
|
+
copy: jest.fn(() => Promise.resolve()),
|
|
11
|
+
checkExists: jest.fn(() => Promise.resolve(true)),
|
|
12
|
+
createDirectory: jest.fn(() => Promise.resolve()),
|
|
13
13
|
}));
|
|
14
14
|
|
|
15
|
-
jest.mock('./
|
|
16
|
-
|
|
17
|
-
return Promise.resolve(target);
|
|
18
|
-
},
|
|
15
|
+
jest.mock('./archive', () => ({
|
|
16
|
+
createTgz: jest.fn(() => Promise.resolve()),
|
|
19
17
|
}));
|
|
20
18
|
|
|
21
19
|
describe('Pack Module', () => {
|
|
@@ -51,7 +49,7 @@ describe('Pack Module', () => {
|
|
|
51
49
|
|
|
52
50
|
it('createPilePackage source <> target', async () => {
|
|
53
51
|
json = { name: 'foo', version: '1.0.0' };
|
|
54
|
-
const path = resolve('./', 'foo-1.0.0.tgz');
|
|
55
|
-
await expect(createPiletPackage('./', '', 'test')).resolves.toEqual(
|
|
52
|
+
const path = resolve('./', 'test', 'foo-1.0.0.tgz');
|
|
53
|
+
await expect(createPiletPackage('./', '', 'test')).resolves.toEqual(path);
|
|
56
54
|
});
|
|
57
55
|
});
|
package/src/common/pack.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tmpdir } from 'os';
|
|
2
|
+
import { resolve, relative, join, dirname, basename } from 'path';
|
|
3
|
+
import { createTgz } from './archive';
|
|
4
|
+
import { onlyUnique } from './utils';
|
|
2
5
|
import { log, progress, fail } from './log';
|
|
3
|
-
import { readJson,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
import { readJson, copy, removeDirectory, checkExists, makeTempDir, createDirectory } from './io';
|
|
7
|
+
import { getPossiblePiletMainPaths } from './inspect';
|
|
8
|
+
|
|
9
|
+
async function getPiletContentDir(root: string, packageData: any) {
|
|
10
|
+
const paths = getPossiblePiletMainPaths(packageData);
|
|
11
|
+
|
|
12
|
+
for (const path of paths) {
|
|
13
|
+
const file = resolve(root, path);
|
|
14
|
+
|
|
15
|
+
if (await checkExists(file)) {
|
|
16
|
+
return dirname(file);
|
|
17
|
+
}
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
return
|
|
20
|
+
return root;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export async function createPiletPackage(baseDir: string, source: string, target: string) {
|
|
@@ -36,13 +39,49 @@ export async function createPiletPackage(baseDir: string, source: string, target
|
|
|
36
39
|
fail('packageJsonMissingVersion_0022');
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const file =
|
|
42
|
+
const isFileTarget = target.endsWith('.tgz');
|
|
43
|
+
progress(`Packing pilet in "${root}" ...`);
|
|
44
|
+
|
|
45
|
+
const pckgName = pckg.name.replace(/@/g, '').replace(/\//g, '-');
|
|
46
|
+
const id = `${pckgName}-${pckg.version}`;
|
|
47
|
+
const name = isFileTarget ? basename(target) : `${id}.tgz`;
|
|
48
|
+
const file = isFileTarget ? dest : resolve(dest, name);
|
|
49
|
+
log('generalDebug_0003', `Assume package name "${name}".`);
|
|
50
|
+
|
|
51
|
+
const content = await getPiletContentDir(root, pckg);
|
|
52
|
+
const files = [resolve(root, 'package.json'), content];
|
|
53
|
+
const readme = resolve(root, 'README.md');
|
|
54
|
+
|
|
55
|
+
if (Array.isArray(pckg.files)) {
|
|
56
|
+
files.push(...pckg.files.map((f) => resolve(root, f)));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (await checkExists(readme)) {
|
|
60
|
+
files.push(readme);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const prefix = join(tmpdir(), `${id}-`);
|
|
64
|
+
const cwd = await makeTempDir(prefix);
|
|
65
|
+
log('generalDebug_0003', `Creating package with content from "${content}" ...`);
|
|
66
|
+
|
|
67
|
+
await Promise.all(files.filter(onlyUnique).map((file) => copy(file, resolve(cwd, relative(root, file)))));
|
|
68
|
+
|
|
69
|
+
log('generalDebug_0003', `Creating directory if not exist for "${file}" ...`);
|
|
70
|
+
|
|
71
|
+
await createDirectory(dirname(file));
|
|
72
|
+
|
|
73
|
+
log('generalDebug_0003', `Creating compressed archive at "${file}" relative to "${root}" ...`);
|
|
74
|
+
|
|
75
|
+
await createTgz(
|
|
76
|
+
file,
|
|
77
|
+
cwd,
|
|
78
|
+
files.map((f) => relative(root, f)),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
log('generalDebug_0003', `Successfully created package from "${cwd}".`);
|
|
82
|
+
|
|
83
|
+
await removeDirectory(cwd);
|
|
84
|
+
|
|
46
85
|
log('generalDebug_0003', `Packed file "${file}".`);
|
|
47
86
|
return file;
|
|
48
87
|
}
|