piral-cli 0.14.0-pre.2983 → 0.14.0-pre.3074
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/lib/api.js +23 -23
- package/lib/api.js.map +1 -1
- package/lib/apps/build-pilet.js +18 -16
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.js +35 -34
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.js +28 -27
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.js +15 -14
- 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/new-pilet.js +40 -39
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +21 -20
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/pack-pilet.js +6 -4
- package/lib/apps/pack-pilet.js.map +1 -1
- package/lib/apps/publish-pilet.js +48 -47
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.js +23 -22
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +34 -33
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.js +20 -19
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/apps/validate-pilet.js +13 -11
- package/lib/apps/validate-pilet.js.map +1 -1
- package/lib/apps/validate-piral.js +12 -10
- package/lib/apps/validate-piral.js.map +1 -1
- package/lib/bundler.js +18 -18
- package/lib/bundler.js.map +1 -1
- package/lib/cli.js +2 -2
- package/lib/cli.js.map +1 -1
- package/lib/commands.js +12 -12
- package/lib/commands.js.map +1 -1
- package/lib/common/archive.js +8 -8
- package/lib/common/archive.js.map +1 -1
- package/lib/common/browser.js +2 -2
- package/lib/common/browser.js.map +1 -1
- package/lib/common/clients/lerna.js +4 -4
- package/lib/common/clients/lerna.js.map +1 -1
- package/lib/common/clients/npm.js +12 -12
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnpm.js +5 -5
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/clients/yarn.js +5 -5
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/compatibility.js +9 -9
- package/lib/common/compatibility.js.map +1 -1
- package/lib/common/config.d.ts +5 -1
- package/lib/common/config.js +2 -1
- package/lib/common/config.js.map +1 -1
- package/lib/common/declaration.js +19 -19
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emulator.js +23 -23
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/envs.js +3 -3
- 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 +1 -0
- package/lib/common/http.js +28 -14
- package/lib/common/http.js.map +1 -1
- package/lib/common/injectors.js +4 -4
- package/lib/common/injectors.js.map +1 -1
- package/lib/common/inspect.js +4 -4
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/io.d.ts +1 -1
- package/lib/common/io.js +114 -93
- package/lib/common/io.js.map +1 -1
- package/lib/common/language.js +2 -2
- package/lib/common/language.js.map +1 -1
- package/lib/common/log.js +8 -8
- package/lib/common/log.js.map +1 -1
- package/lib/common/npm.js +43 -43
- package/lib/common/npm.js.map +1 -1
- package/lib/common/pack.js +18 -18
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.d.ts +3 -1
- package/lib/common/package.js +181 -80
- package/lib/common/package.js.map +1 -1
- package/lib/common/patcher.js +20 -20
- package/lib/common/patcher.js.map +1 -1
- package/lib/common/port.js +3 -3
- 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.js +15 -15
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/scripts.js +5 -5
- package/lib/common/scripts.js.map +1 -1
- package/lib/common/template.js +4 -4
- package/lib/common/template.js.map +1 -1
- package/lib/external/index.js +1369 -611
- package/lib/helpers.js +1 -1
- package/lib/helpers.js.map +1 -1
- package/lib/inject.js +2 -2
- package/lib/inject.js.map +1 -1
- package/lib/injectors/pilet.d.ts +1 -10
- package/lib/injectors/pilet.js +74 -27
- package/lib/injectors/pilet.js.map +1 -1
- package/lib/injectors/piral.js +4 -4
- package/lib/injectors/piral.js.map +1 -1
- package/lib/messages.d.ts +7 -2
- package/lib/messages.js +7 -2
- 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/plugin.js +10 -10
- package/lib/plugin.js.map +1 -1
- package/lib/release.js +3 -3
- 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 +7 -7
- package/lib/rules/index.js.map +1 -1
- package/lib/rules/pilet-has-externals-as-peers.js +3 -3
- package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
- package/lib/rules/pilet-has-no-self-reference.js +1 -1
- package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
- package/lib/rules/pilet-stays-small.js +3 -3
- package/lib/rules/pilet-stays-small.js.map +1 -1
- package/lib/rules/pilet-uses-latest-piral.js +1 -1
- package/lib/rules/pilet-uses-latest-piral.js.map +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-files.js +5 -5
- package/lib/rules/piral-has-valid-files.js.map +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 +8 -0
- package/lib/types/public.d.ts +4 -2
- package/package.json +2 -2
- package/src/apps/build-pilet.ts +8 -5
- package/src/apps/build-piral.ts +4 -3
- package/src/apps/debug-pilet.ts +5 -4
- package/src/apps/debug-piral.ts +2 -1
- package/src/apps/declaration-piral.ts +3 -1
- package/src/apps/new-pilet.ts +3 -2
- package/src/apps/new-piral.ts +2 -1
- package/src/apps/pack-pilet.ts +3 -1
- package/src/apps/publish-pilet.ts +6 -5
- package/src/apps/publish-piral.ts +3 -2
- package/src/apps/upgrade-pilet.ts +4 -3
- package/src/apps/upgrade-piral.ts +2 -1
- package/src/apps/validate-pilet.ts +5 -2
- package/src/apps/validate-piral.ts +3 -1
- package/src/bundler.test.ts +18 -22
- package/src/common/config.ts +6 -1
- package/src/common/hash.ts +5 -0
- package/src/common/http.ts +18 -4
- package/src/common/io.ts +56 -33
- package/src/common/package.ts +118 -8
- package/src/helpers.ts +1 -1
- package/src/injectors/pilet.ts +82 -22
- package/src/messages.ts +7 -2
- package/src/types/common.ts +9 -0
- package/src/types/public.ts +4 -1
package/src/apps/new-pilet.ts
CHANGED
|
@@ -120,10 +120,11 @@ export async function newPilet(baseDir = process.cwd(), options: NewPiletOptions
|
|
|
120
120
|
bundlerName = newPiletDefaults.bundlerName,
|
|
121
121
|
variables = newPiletDefaults.variables,
|
|
122
122
|
} = options;
|
|
123
|
+
const fullBase = resolve(process.cwd(), baseDir);
|
|
124
|
+
const root = resolve(fullBase, target);
|
|
123
125
|
setLogLevel(logLevel);
|
|
124
126
|
progress('Preparing source and target ...');
|
|
125
|
-
const
|
|
126
|
-
const [sourceName, sourceVersion, hadVersion, type] = await dissectPackageName(baseDir, source);
|
|
127
|
+
const [sourceName, sourceVersion, hadVersion, type] = await dissectPackageName(fullBase, source);
|
|
127
128
|
const success = await createDirectory(root);
|
|
128
129
|
|
|
129
130
|
if (success) {
|
package/src/apps/new-piral.ts
CHANGED
|
@@ -118,9 +118,10 @@ export async function newPiral(baseDir = process.cwd(), options: NewPiralOptions
|
|
|
118
118
|
bundlerName = newPiralDefaults.bundlerName,
|
|
119
119
|
variables = newPiralDefaults.variables,
|
|
120
120
|
} = options;
|
|
121
|
+
const fullBase = resolve(process.cwd(), baseDir);
|
|
122
|
+
const root = resolve(fullBase, target);
|
|
121
123
|
setLogLevel(logLevel);
|
|
122
124
|
progress('Preparing source and target ...');
|
|
123
|
-
const root = resolve(baseDir, target);
|
|
124
125
|
const success = await createDirectory(root);
|
|
125
126
|
|
|
126
127
|
if (success) {
|
package/src/apps/pack-pilet.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
1
2
|
import { createPiletPackage, logDone, setLogLevel, progress } from '../common';
|
|
2
3
|
import { LogLevels } from '../types';
|
|
3
4
|
|
|
@@ -30,8 +31,9 @@ export async function packPilet(baseDir = process.cwd(), options: PackPiletOptio
|
|
|
30
31
|
target = packPiletDefaults.target,
|
|
31
32
|
logLevel = packPiletDefaults.logLevel,
|
|
32
33
|
} = options;
|
|
34
|
+
const fullBase = resolve(process.cwd(), baseDir);
|
|
33
35
|
setLogLevel(logLevel);
|
|
34
36
|
progress('Reading configuration ...');
|
|
35
|
-
await createPiletPackage(
|
|
37
|
+
await createPiletPackage(fullBase, source, target);
|
|
36
38
|
logDone(`Pilet packed successfully!`);
|
|
37
39
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { relative, join, dirname, basename } from 'path';
|
|
1
|
+
import { relative, join, dirname, basename, resolve } from 'path';
|
|
2
2
|
import { buildPilet } from './build-pilet';
|
|
3
3
|
import { LogLevels, PiletSchemaVersion, PiletPublishSource } from '../types';
|
|
4
4
|
import {
|
|
@@ -76,7 +76,7 @@ export const publishPiletDefaults: PublishPiletOptions = {
|
|
|
76
76
|
fresh: false,
|
|
77
77
|
cert: undefined,
|
|
78
78
|
logLevel: LogLevels.info,
|
|
79
|
-
schemaVersion:
|
|
79
|
+
schemaVersion: config.schemaVersion,
|
|
80
80
|
from: 'local',
|
|
81
81
|
fields: {},
|
|
82
82
|
};
|
|
@@ -134,6 +134,7 @@ export async function publishPilet(baseDir = process.cwd(), options: PublishPile
|
|
|
134
134
|
cert = config.cert ?? publishPiletDefaults.cert,
|
|
135
135
|
fields = publishPiletDefaults.fields,
|
|
136
136
|
} = options;
|
|
137
|
+
const fullBase = resolve(process.cwd(), baseDir);
|
|
137
138
|
setLogLevel(logLevel);
|
|
138
139
|
progress('Reading configuration ...');
|
|
139
140
|
|
|
@@ -152,7 +153,7 @@ export async function publishPilet(baseDir = process.cwd(), options: PublishPile
|
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
log('generalDebug_0003', 'Getting the tgz files ...');
|
|
155
|
-
const files = await getFiles(
|
|
156
|
+
const files = await getFiles(fullBase, source, from, fresh, schemaVersion, ca);
|
|
156
157
|
const successfulUploads: Array<string> = [];
|
|
157
158
|
log('generalDebug_0003', 'Received available tgz files.');
|
|
158
159
|
|
|
@@ -164,8 +165,8 @@ export async function publishPilet(baseDir = process.cwd(), options: PublishPile
|
|
|
164
165
|
|
|
165
166
|
for (const file of files) {
|
|
166
167
|
log('generalDebug_0003', 'Reading the file for upload ...');
|
|
167
|
-
const fileName = relative(
|
|
168
|
-
const content = await readBinary(
|
|
168
|
+
const fileName = relative(fullBase, file);
|
|
169
|
+
const content = await readBinary(fullBase, fileName);
|
|
169
170
|
|
|
170
171
|
if (content) {
|
|
171
172
|
progress(`Publishing "%s" ...`, file, url);
|
|
@@ -87,6 +87,7 @@ export async function publishPiral(baseDir = process.cwd(), options: PublishPira
|
|
|
87
87
|
fields = publishPiralDefaults.fields,
|
|
88
88
|
provider = publishPiralDefaults.provider,
|
|
89
89
|
} = options;
|
|
90
|
+
const fullBase = resolve(process.cwd(), baseDir);
|
|
90
91
|
setLogLevel(logLevel);
|
|
91
92
|
|
|
92
93
|
if (type === 'emulator-sources') {
|
|
@@ -97,14 +98,14 @@ export async function publishPiral(baseDir = process.cwd(), options: PublishPira
|
|
|
97
98
|
|
|
98
99
|
if (type !== 'release') {
|
|
99
100
|
progress('Publishing emulator package ...');
|
|
100
|
-
await publishEmulator(
|
|
101
|
+
await publishEmulator(fullBase, source, fields);
|
|
101
102
|
logDone(`Successfully published emulator.`);
|
|
102
103
|
logReset();
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
if (type !== 'emulator') {
|
|
106
107
|
progress('Publishing release files ...');
|
|
107
|
-
await publishRelease(
|
|
108
|
+
await publishRelease(fullBase, source, provider, fields);
|
|
108
109
|
logDone(`Successfully published release.`);
|
|
109
110
|
logReset();
|
|
110
111
|
}
|
|
@@ -82,8 +82,9 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
82
82
|
logLevel = upgradePiletDefaults.logLevel,
|
|
83
83
|
install = upgradePiletDefaults.install,
|
|
84
84
|
} = options;
|
|
85
|
+
const fullBase = resolve(process.cwd(), baseDir);
|
|
86
|
+
const root = resolve(fullBase, target);
|
|
85
87
|
setLogLevel(logLevel);
|
|
86
|
-
const root = resolve(baseDir, target);
|
|
87
88
|
const valid = await checkExistingDirectory(root);
|
|
88
89
|
|
|
89
90
|
if (!valid) {
|
|
@@ -107,9 +108,9 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
107
108
|
fail('invalidPiralReference_0043');
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
const monorepoRef = await isMonorepoPackageRef(sourceName,
|
|
111
|
+
const monorepoRef = await isMonorepoPackageRef(sourceName, fullBase);
|
|
111
112
|
const [packageRef, packageVersion] = await getCurrentPackageDetails(
|
|
112
|
-
|
|
113
|
+
fullBase,
|
|
113
114
|
sourceName,
|
|
114
115
|
currentVersion,
|
|
115
116
|
version,
|
|
@@ -81,8 +81,9 @@ export async function upgradePiral(baseDir = process.cwd(), options: UpgradePira
|
|
|
81
81
|
logLevel = upgradePiralDefaults.logLevel,
|
|
82
82
|
install = upgradePiralDefaults.install,
|
|
83
83
|
} = options;
|
|
84
|
+
const fullBase = resolve(process.cwd(), baseDir);
|
|
85
|
+
const root = resolve(fullBase, target);
|
|
84
86
|
setLogLevel(logLevel);
|
|
85
|
-
const root = resolve(baseDir, target);
|
|
86
87
|
const valid = await checkExistingDirectory(root);
|
|
87
88
|
const exists = await checkExists(join(root, 'package.json'));
|
|
88
89
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, dirname } from 'path';
|
|
1
|
+
import { join, dirname, resolve } from 'path';
|
|
2
2
|
import { ruleSummary, runRules, retrievePiletData, getPiletsInfo, setLogLevel, progress, log } from '../common';
|
|
3
3
|
import { getPiletRules } from '../rules';
|
|
4
4
|
import { PiletRuleContext, LogLevels } from '../types';
|
|
@@ -32,11 +32,12 @@ export async function validatePilet(baseDir = process.cwd(), options: ValidatPil
|
|
|
32
32
|
logLevel = validatePiletDefaults.logLevel,
|
|
33
33
|
app = validatePiletDefaults.app,
|
|
34
34
|
} = options;
|
|
35
|
+
const fullBase = resolve(process.cwd(), baseDir);
|
|
35
36
|
setLogLevel(logLevel);
|
|
36
37
|
progress('Reading configuration ...');
|
|
37
38
|
|
|
38
39
|
const rules = await getPiletRules();
|
|
39
|
-
const entryFile = join(
|
|
40
|
+
const entryFile = join(fullBase, entry);
|
|
40
41
|
const target = dirname(entryFile);
|
|
41
42
|
const {
|
|
42
43
|
dependencies,
|
|
@@ -44,6 +45,7 @@ export async function validatePilet(baseDir = process.cwd(), options: ValidatPil
|
|
|
44
45
|
devDependencies,
|
|
45
46
|
peerModules,
|
|
46
47
|
root,
|
|
48
|
+
importmap,
|
|
47
49
|
ignored: _0,
|
|
48
50
|
emulator: _1,
|
|
49
51
|
...data
|
|
@@ -63,6 +65,7 @@ export async function validatePilet(baseDir = process.cwd(), options: ValidatPil
|
|
|
63
65
|
dependencies,
|
|
64
66
|
devDependencies,
|
|
65
67
|
peerDependencies,
|
|
68
|
+
importmap,
|
|
66
69
|
peerModules,
|
|
67
70
|
root,
|
|
68
71
|
data,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
1
2
|
import { retrievePiralRoot, retrievePiletsInfo, ruleSummary, runRules, config } from '../common';
|
|
2
3
|
import { setLogLevel, progress, log, checkCliCompatibility } from '../common';
|
|
3
4
|
import { getPiralRules } from '../rules';
|
|
@@ -22,11 +23,12 @@ export const validatePiralDefaults: ValidatPiralOptions = {
|
|
|
22
23
|
|
|
23
24
|
export async function validatePiral(baseDir = process.cwd(), options: ValidatPiralOptions = {}) {
|
|
24
25
|
const { entry = validatePiralDefaults.entry, logLevel = validatePiralDefaults.logLevel } = options;
|
|
26
|
+
const fullBase = resolve(process.cwd(), baseDir);
|
|
25
27
|
setLogLevel(logLevel);
|
|
26
28
|
progress('Reading configuration ...');
|
|
27
29
|
|
|
28
30
|
const rules = await getPiralRules();
|
|
29
|
-
const entryFiles = await retrievePiralRoot(
|
|
31
|
+
const entryFiles = await retrievePiralRoot(fullBase, entry);
|
|
30
32
|
const { root, dependencies, ignored: _, ...info } = await retrievePiletsInfo(entryFiles);
|
|
31
33
|
const errors: Array<string> = [];
|
|
32
34
|
const warnings: Array<string> = [];
|
package/src/bundler.test.ts
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
callPiralDebug,
|
|
7
7
|
callDebugPiralFromMonoRepo,
|
|
8
8
|
} from './bundler';
|
|
9
|
+
import * as common from './common';
|
|
9
10
|
|
|
10
|
-
let common: any;
|
|
11
11
|
let defaults = {
|
|
12
12
|
bundler: false,
|
|
13
13
|
};
|
|
@@ -29,27 +29,23 @@ jest.mock('./inject', () => ({
|
|
|
29
29
|
},
|
|
30
30
|
}));
|
|
31
31
|
|
|
32
|
-
jest.mock(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
patchModules: jest.fn(),
|
|
50
|
-
logReset() {},
|
|
51
|
-
}),
|
|
52
|
-
);
|
|
32
|
+
jest.mock('./common', () => ({
|
|
33
|
+
config: {
|
|
34
|
+
bundler: 'parcel',
|
|
35
|
+
},
|
|
36
|
+
cliVersion: '1.0.0',
|
|
37
|
+
installPackage: jest.fn(),
|
|
38
|
+
fail(msg) {
|
|
39
|
+
throw new Error(msg);
|
|
40
|
+
},
|
|
41
|
+
progress() {},
|
|
42
|
+
log() {},
|
|
43
|
+
determineNpmClient() {
|
|
44
|
+
return 'npm';
|
|
45
|
+
},
|
|
46
|
+
patchModules: jest.fn(),
|
|
47
|
+
logReset() {},
|
|
48
|
+
}));
|
|
53
49
|
|
|
54
50
|
describe('Piral CLI Bundler Module', () => {
|
|
55
51
|
it('fails if no default bundler can be installed, but required', async () => {
|
package/src/common/config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { rc } from '../external';
|
|
2
|
-
import { NpmClientType } from '../types';
|
|
2
|
+
import { NpmClientType, PiletSchemaVersion } from '../types';
|
|
3
3
|
|
|
4
4
|
export interface PiralCliConfig {
|
|
5
5
|
/**
|
|
@@ -37,6 +37,10 @@ export interface PiralCliConfig {
|
|
|
37
37
|
* Sets the validators configuration for a Piral instance.
|
|
38
38
|
*/
|
|
39
39
|
validators?: Record<string, any>;
|
|
40
|
+
/**
|
|
41
|
+
* Sets the schema version to be used for pilets.
|
|
42
|
+
*/
|
|
43
|
+
schemaVersion?: PiletSchemaVersion;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
export const config: PiralCliConfig = rc('piral', {
|
|
@@ -48,4 +52,5 @@ export const config: PiralCliConfig = rc('piral', {
|
|
|
48
52
|
bundler: 'webpack',
|
|
49
53
|
piletApi: '/$pilet-api',
|
|
50
54
|
validators: {},
|
|
55
|
+
schemaVersion: 'v2',
|
|
51
56
|
});
|
package/src/common/hash.ts
CHANGED
|
@@ -7,3 +7,8 @@ export function computeHash(content: string | Buffer = '') {
|
|
|
7
7
|
export function computeMd5(content: string | Buffer = '') {
|
|
8
8
|
return createHash('md5').update(content).digest('hex');
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
export function computeIntegrity(content: string) {
|
|
12
|
+
const sum = createHash('sha256').update(content).digest('base64');
|
|
13
|
+
return `sha256-${sum}`;
|
|
14
|
+
}
|
package/src/common/http.ts
CHANGED
|
@@ -4,9 +4,13 @@ import { Stream } from 'stream';
|
|
|
4
4
|
import { platform, tmpdir } from 'os';
|
|
5
5
|
import { createWriteStream } from 'fs';
|
|
6
6
|
import { log } from './log';
|
|
7
|
+
import { computeHash } from './hash';
|
|
7
8
|
import { axios, FormData } from '../external';
|
|
8
9
|
|
|
9
10
|
const os = platform();
|
|
11
|
+
const standardHeaders = {
|
|
12
|
+
'user-agent': `piral-cli/http.node-${os}`,
|
|
13
|
+
};
|
|
10
14
|
|
|
11
15
|
function getMessage(body: string | { message?: string }) {
|
|
12
16
|
if (typeof body === 'string') {
|
|
@@ -36,14 +40,24 @@ function streamToFile(source: Stream, target: string) {
|
|
|
36
40
|
});
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
export function getHashFromUrl(target: string): Promise<string> {
|
|
44
|
+
return axios.default
|
|
45
|
+
.get<Buffer>(target, {
|
|
46
|
+
responseType: 'arraybuffer',
|
|
47
|
+
headers: standardHeaders,
|
|
48
|
+
})
|
|
49
|
+
.then((res) => {
|
|
50
|
+
log('generalDebug_0003', `Received the contents from "${target}" (status: ${res.status}).`);
|
|
51
|
+
return computeHash(res.data);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
39
55
|
export function downloadFile(target: string, ca?: Buffer): Promise<Array<string>> {
|
|
40
56
|
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
41
57
|
return axios.default
|
|
42
58
|
.get<Stream>(target, {
|
|
43
59
|
responseType: 'stream',
|
|
44
|
-
headers:
|
|
45
|
-
'user-agent': `piral-cli/http.node-${os}`,
|
|
46
|
-
},
|
|
60
|
+
headers: standardHeaders,
|
|
47
61
|
httpsAgent,
|
|
48
62
|
})
|
|
49
63
|
.then((res) => {
|
|
@@ -80,7 +94,7 @@ export function postFile(
|
|
|
80
94
|
|
|
81
95
|
const headers: Record<string, string> = {
|
|
82
96
|
...form.getHeaders(),
|
|
83
|
-
|
|
97
|
+
...standardHeaders,
|
|
84
98
|
};
|
|
85
99
|
|
|
86
100
|
if (key) {
|
package/src/common/io.ts
CHANGED
|
@@ -205,16 +205,22 @@ async function matchAnyPattern(baseDir: string, pattern: AnyPattern) {
|
|
|
205
205
|
|
|
206
206
|
const preferences = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.esm', '.es', '.es6', '.html'];
|
|
207
207
|
|
|
208
|
-
export async function
|
|
208
|
+
export async function matchAnyPilet(baseDir: string, patterns: Array<string>) {
|
|
209
209
|
const matches: Array<string> = [];
|
|
210
|
+
const pilets: Array<string> = [];
|
|
211
|
+
const matched = (name: string, path: string) => {
|
|
212
|
+
pilets.push(name);
|
|
213
|
+
matches.push(path);
|
|
214
|
+
};
|
|
215
|
+
const nameOfPackageJson = 'package.json';
|
|
210
216
|
const exts = preferences.map((s) => s.substr(1)).join(',');
|
|
211
217
|
const allPatterns = patterns.reduce<Array<AnyPattern>>((agg, curr) => {
|
|
212
218
|
const patterns = [];
|
|
213
219
|
|
|
214
|
-
if (/[a-zA-Z0-9
|
|
215
|
-
patterns.push(curr, `${curr}.{${exts}}`, `${curr}
|
|
220
|
+
if (/[a-zA-Z0-9\-\*]+$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
|
|
221
|
+
patterns.push(curr, `${curr}.{${exts}}`, `${curr}/${nameOfPackageJson}`);
|
|
216
222
|
} else if (curr.endsWith('/')) {
|
|
217
|
-
patterns.push(`${curr}index.{${exts}}`, `${curr}
|
|
223
|
+
patterns.push(`${curr}index.{${exts}}`, `${curr}${nameOfPackageJson}`);
|
|
218
224
|
} else {
|
|
219
225
|
patterns.push(curr);
|
|
220
226
|
}
|
|
@@ -227,43 +233,60 @@ export async function matchAny(baseDir: string, patterns: Array<string>) {
|
|
|
227
233
|
allPatterns.map((patterns) =>
|
|
228
234
|
matchAnyPattern(baseDir, patterns).then(async ({ results, pattern }) => {
|
|
229
235
|
if (!results.length) {
|
|
230
|
-
|
|
236
|
+
log('generalDebug_0003', `Found no potential entry points using "${pattern}".`);
|
|
231
237
|
} else {
|
|
238
|
+
//TODO -> shouldn't take the first one,
|
|
239
|
+
// should be the first one, yes, but, PER pilet
|
|
240
|
+
// so that multiple pilets can be considered, too
|
|
232
241
|
log('generalDebug_0003', `Found ${results.length} potential entry points in "${pattern}".`);
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
242
|
+
|
|
243
|
+
for (const result of results) {
|
|
244
|
+
const fileName = basename(result);
|
|
245
|
+
|
|
246
|
+
if (fileName === nameOfPackageJson) {
|
|
247
|
+
log('generalDebug_0003', `Entry point is a "${nameOfPackageJson}" and needs further inspection.`);
|
|
248
|
+
const targetDir = dirname(result);
|
|
249
|
+
const { source, name } = await readJson(targetDir, fileName);
|
|
250
|
+
|
|
251
|
+
if (!pilets.includes(name)) {
|
|
252
|
+
if (typeof source === 'string') {
|
|
253
|
+
log('generalDebug_0003', `Found a "source" field with value "${source}".`);
|
|
254
|
+
const target = resolve(targetDir, source);
|
|
255
|
+
const exists = await checkExists(target);
|
|
256
|
+
|
|
257
|
+
if (exists) {
|
|
258
|
+
log('generalDebug_0003', `Taking existing target as "${target}".`);
|
|
259
|
+
matched(name, target);
|
|
260
|
+
} else {
|
|
261
|
+
log('generalDebug_0003', `Source target "${target}" does not exist. Skipped.`);
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
log('generalDebug_0003', `No "source" field found. Trying combinations in "src".`);
|
|
265
|
+
const files = await matchPattern(targetDir, `src/index.{${exts}}`);
|
|
266
|
+
|
|
267
|
+
if (files.length > 0) {
|
|
268
|
+
log('generalDebug_0003', `Found a result; taking "${files[0]}".`);
|
|
269
|
+
matched(name, files[0]);
|
|
270
|
+
} else {
|
|
271
|
+
log('generalDebug_0003', `Found no results in "src". Skipped.`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
252
274
|
}
|
|
253
275
|
} else {
|
|
254
|
-
|
|
255
|
-
|
|
276
|
+
const packageJson = await findFile(result, nameOfPackageJson);
|
|
277
|
+
|
|
278
|
+
if (packageJson) {
|
|
279
|
+
const targetDir = dirname(packageJson);
|
|
280
|
+
const { name } = await readJson(targetDir, nameOfPackageJson);
|
|
256
281
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
282
|
+
if (!pilets.includes(name)) {
|
|
283
|
+
log('generalDebug_0003', `Entry point result is "${result}".`);
|
|
284
|
+
matched(name, result);
|
|
285
|
+
}
|
|
260
286
|
} else {
|
|
261
|
-
log('generalDebug_0003', `
|
|
287
|
+
log('generalDebug_0003', `Could not find "${nameOfPackageJson}" for entry "${result}". Skipping.`);
|
|
262
288
|
}
|
|
263
289
|
}
|
|
264
|
-
} else {
|
|
265
|
-
log('generalDebug_0003', `Entry point result is "${firstResult}".`);
|
|
266
|
-
matches.push(firstResult);
|
|
267
290
|
}
|
|
268
291
|
}
|
|
269
292
|
}),
|