piral-cli 0.14.3-beta.3295 → 0.14.3-beta.3303
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/apps/build-pilet.js +35 -9
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.js +4 -2
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/publish-pilet.d.ts +8 -0
- package/lib/apps/publish-pilet.js +45 -16
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/build/run-build-piral.js +3 -3
- package/lib/build/run-build-piral.js.map +1 -1
- package/lib/commands.js +5 -0
- package/lib/commands.js.map +1 -1
- package/lib/common/constants.d.ts +1 -0
- package/lib/common/constants.js +2 -1
- package/lib/common/constants.js.map +1 -1
- package/lib/common/declaration.js +1 -3
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emulator.js +3 -2
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/envs.js +2 -1
- package/lib/common/envs.js.map +1 -1
- package/lib/common/io.js +12 -4
- package/lib/common/io.js.map +1 -1
- package/lib/common/npm.d.ts +2 -3
- package/lib/common/npm.js +21 -10
- package/lib/common/npm.js.map +1 -1
- package/lib/common/package.js +3 -2
- package/lib/common/package.js.map +1 -1
- package/lib/helpers.js +1 -1
- package/lib/helpers.js.map +1 -1
- package/lib/types/public.d.ts +2 -1
- package/package.json +2 -2
- package/src/apps/build-pilet.ts +67 -21
- package/src/apps/build-piral.ts +16 -6
- package/src/apps/publish-pilet.ts +78 -15
- package/src/apps/publish-piral.ts +1 -1
- package/src/build/run-build-piral.ts +3 -1
- package/src/commands.ts +5 -0
- package/src/common/constants.ts +1 -0
- package/src/common/declaration.ts +1 -3
- package/src/common/emulator.ts +6 -3
- package/src/common/envs.ts +2 -1
- package/src/common/io.ts +14 -4
- package/src/common/npm.test.ts +7 -7
- package/src/common/npm.ts +28 -8
- package/src/common/package.test.ts +1 -7
- package/src/common/package.ts +6 -2
- package/src/helpers.ts +1 -1
- package/src/types/public.ts +2 -1
package/src/apps/build-piral.ts
CHANGED
|
@@ -194,11 +194,16 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
|
|
|
194
194
|
await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, targetDir, name });
|
|
195
195
|
|
|
196
196
|
logInfo(`Bundle ${emulatorName} ...`);
|
|
197
|
-
const {
|
|
197
|
+
const {
|
|
198
|
+
dir: outDir,
|
|
199
|
+
name: outFile,
|
|
200
|
+
hash,
|
|
201
|
+
} = await callPiralBuild(
|
|
198
202
|
{
|
|
199
203
|
root,
|
|
200
204
|
piral: name,
|
|
201
205
|
emulator: true,
|
|
206
|
+
standalone: false,
|
|
202
207
|
optimizeModules,
|
|
203
208
|
sourceMaps,
|
|
204
209
|
contentHash,
|
|
@@ -219,11 +224,11 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
|
|
|
219
224
|
|
|
220
225
|
await runLifecycle(root, scripts, 'piral:postbuild');
|
|
221
226
|
await runLifecycle(root, scripts, `piral:postbuild-${emulatorName}`);
|
|
222
|
-
|
|
227
|
+
|
|
223
228
|
await hooks.beforeEmulator?.({ root, externals, targetDir, outDir });
|
|
224
229
|
|
|
225
230
|
const rootDir = await createEmulatorSources(root, outDir, outFile, logLevel);
|
|
226
|
-
|
|
231
|
+
|
|
227
232
|
await hooks.afterEmulator?.({ root, externals, targetDir, outDir, rootDir });
|
|
228
233
|
|
|
229
234
|
if (type !== emulatorSourcesName) {
|
|
@@ -247,14 +252,19 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
|
|
|
247
252
|
await removeDirectory(targetDir);
|
|
248
253
|
|
|
249
254
|
logInfo(`Bundle ${releaseName} ...`);
|
|
250
|
-
|
|
255
|
+
|
|
251
256
|
await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, targetDir, name });
|
|
252
257
|
|
|
253
|
-
const {
|
|
258
|
+
const {
|
|
259
|
+
dir: outDir,
|
|
260
|
+
name: outFile,
|
|
261
|
+
hash,
|
|
262
|
+
} = await callPiralBuild(
|
|
254
263
|
{
|
|
255
264
|
root,
|
|
256
265
|
piral: name,
|
|
257
266
|
emulator: false,
|
|
267
|
+
standalone: false,
|
|
258
268
|
optimizeModules,
|
|
259
269
|
sourceMaps,
|
|
260
270
|
contentHash,
|
|
@@ -270,7 +280,7 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
|
|
|
270
280
|
},
|
|
271
281
|
bundlerName,
|
|
272
282
|
);
|
|
273
|
-
|
|
283
|
+
|
|
274
284
|
await hooks.afterBuild?.({ root, publicUrl, externals, entryFiles, targetDir, name, outDir, outFile, hash });
|
|
275
285
|
|
|
276
286
|
await runLifecycle(root, scripts, 'piral:postbuild');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { relative,
|
|
2
|
-
import {
|
|
1
|
+
import { relative, dirname, basename, resolve } from 'path';
|
|
2
|
+
import { callPiletBuild } from '../bundler';
|
|
3
3
|
import { LogLevels, PiletSchemaVersion, PiletPublishSource } from '../types';
|
|
4
4
|
import {
|
|
5
5
|
postFile,
|
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
checkExists,
|
|
16
16
|
findTarball,
|
|
17
17
|
downloadFile,
|
|
18
|
+
matchAnyPilet,
|
|
19
|
+
retrievePiletData,
|
|
20
|
+
removeDirectory,
|
|
21
|
+
logInfo,
|
|
18
22
|
} from '../common';
|
|
19
23
|
|
|
20
24
|
export interface PublishPiletOptions {
|
|
@@ -67,6 +71,16 @@ export interface PublishPiletOptions {
|
|
|
67
71
|
* Places additional fields that should be posted to the feed service.
|
|
68
72
|
*/
|
|
69
73
|
fields?: Record<string, string>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Sets the bundler to use for building, if any specific.
|
|
77
|
+
*/
|
|
78
|
+
bundlerName?: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Additional arguments for a specific bundler.
|
|
82
|
+
*/
|
|
83
|
+
_?: Record<string, any>;
|
|
70
84
|
}
|
|
71
85
|
|
|
72
86
|
export const publishPiletDefaults: PublishPiletOptions = {
|
|
@@ -87,22 +101,69 @@ async function getFiles(
|
|
|
87
101
|
from: PiletPublishSource,
|
|
88
102
|
fresh: boolean,
|
|
89
103
|
schemaVersion: PiletSchemaVersion,
|
|
104
|
+
logLevel: LogLevels,
|
|
105
|
+
bundlerName: string,
|
|
106
|
+
_?: Record<string, any>,
|
|
90
107
|
ca?: Buffer,
|
|
91
108
|
): Promise<Array<string>> {
|
|
92
109
|
if (fresh) {
|
|
93
110
|
log('generalDebug_0003', 'Detected "--fresh". Trying to resolve the package.json.');
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
const allEntries = await matchAnyPilet(baseDir, sources);
|
|
112
|
+
|
|
113
|
+
if (allEntries.length === 0) {
|
|
114
|
+
fail('entryFileMissing_0077');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return await Promise.all(
|
|
118
|
+
allEntries.map(async (entryModule) => {
|
|
119
|
+
const targetDir = dirname(entryModule);
|
|
120
|
+
const { root, piletPackage, importmap, peerDependencies, peerModules, appPackage } = await retrievePiletData(
|
|
121
|
+
targetDir,
|
|
122
|
+
);
|
|
123
|
+
const dest = resolve(root, piletPackage.main);
|
|
124
|
+
const outDir = dirname(dest);
|
|
125
|
+
const outFile = basename(dest);
|
|
126
|
+
const externals = [...Object.keys(peerDependencies), ...peerModules];
|
|
127
|
+
progress('Triggering pilet build ...');
|
|
128
|
+
|
|
129
|
+
if (fresh) {
|
|
130
|
+
progress('Removing output directory ...');
|
|
131
|
+
await removeDirectory(outDir);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
logInfo('Bundle pilet ...');
|
|
135
|
+
|
|
136
|
+
await callPiletBuild(
|
|
137
|
+
{
|
|
138
|
+
root,
|
|
139
|
+
piral: appPackage.name,
|
|
140
|
+
optimizeModules: false,
|
|
141
|
+
sourceMaps: true,
|
|
142
|
+
contentHash: true,
|
|
143
|
+
minify: true,
|
|
144
|
+
externals,
|
|
145
|
+
targetDir,
|
|
146
|
+
importmap,
|
|
147
|
+
outFile,
|
|
148
|
+
outDir,
|
|
149
|
+
entryModule: `./${relative(root, entryModule)}`,
|
|
150
|
+
logLevel,
|
|
151
|
+
version: schemaVersion,
|
|
152
|
+
ignored: [],
|
|
153
|
+
_,
|
|
154
|
+
},
|
|
155
|
+
bundlerName,
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
log('generalDebug_0003', `Pilet "${piletPackage.name}" built successfully!`);
|
|
159
|
+
progress('Triggering pilet pack ...');
|
|
160
|
+
|
|
161
|
+
const file = await createPiletPackage(root, '.', '.');
|
|
162
|
+
log('generalDebug_0003', `Pilet "${piletPackage.name}" packed successfully!`);
|
|
163
|
+
|
|
164
|
+
return file;
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
106
167
|
} else {
|
|
107
168
|
log('generalDebug_0003', `Did not find fresh flag. Trying to match from "${from}".`);
|
|
108
169
|
|
|
@@ -139,6 +200,8 @@ export async function publishPilet(baseDir = process.cwd(), options: PublishPile
|
|
|
139
200
|
schemaVersion = publishPiletDefaults.schemaVersion,
|
|
140
201
|
cert = config.cert ?? publishPiletDefaults.cert,
|
|
141
202
|
fields = publishPiletDefaults.fields,
|
|
203
|
+
_ = {},
|
|
204
|
+
bundlerName,
|
|
142
205
|
} = options;
|
|
143
206
|
const fullBase = resolve(process.cwd(), baseDir);
|
|
144
207
|
setLogLevel(logLevel);
|
|
@@ -160,7 +223,7 @@ export async function publishPilet(baseDir = process.cwd(), options: PublishPile
|
|
|
160
223
|
|
|
161
224
|
log('generalDebug_0003', 'Getting the tgz files ...');
|
|
162
225
|
const sources = Array.isArray(source) ? source : [source];
|
|
163
|
-
const files = await getFiles(fullBase, sources, from, fresh, schemaVersion, ca);
|
|
226
|
+
const files = await getFiles(fullBase, sources, from, fresh, schemaVersion, logLevel, bundlerName, _, ca);
|
|
164
227
|
const successfulUploads: Array<string> = [];
|
|
165
228
|
log('generalDebug_0003', 'Received available tgz files.');
|
|
166
229
|
|
|
@@ -7,6 +7,7 @@ function run(
|
|
|
7
7
|
root: string,
|
|
8
8
|
piral: string,
|
|
9
9
|
emulator: boolean,
|
|
10
|
+
standalone: boolean,
|
|
10
11
|
sourceMaps: boolean,
|
|
11
12
|
contentHash: boolean,
|
|
12
13
|
minify: boolean,
|
|
@@ -22,7 +23,7 @@ function run(
|
|
|
22
23
|
production: !emulator,
|
|
23
24
|
root,
|
|
24
25
|
debugPiral: emulator,
|
|
25
|
-
debugPilet: emulator,
|
|
26
|
+
debugPilet: emulator || standalone,
|
|
26
27
|
piral,
|
|
27
28
|
dependencies: externals,
|
|
28
29
|
});
|
|
@@ -56,6 +57,7 @@ process.on('message', async (msg) => {
|
|
|
56
57
|
process.cwd(),
|
|
57
58
|
msg.piral,
|
|
58
59
|
msg.emulator,
|
|
60
|
+
msg.standalone,
|
|
59
61
|
msg.sourceMaps,
|
|
60
62
|
msg.contentHash,
|
|
61
63
|
msg.minify,
|
package/src/commands.ts
CHANGED
|
@@ -573,6 +573,9 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
573
573
|
.choices('schema', schemaKeys)
|
|
574
574
|
.describe('schema', 'Sets the schema to be used when making a fresh build of the pilet.')
|
|
575
575
|
.default('schema', apps.publishPiletDefaults.schemaVersion)
|
|
576
|
+
.choices('bundler', availableBundlers)
|
|
577
|
+
.describe('bundler', 'Sets the bundler to use.')
|
|
578
|
+
.default('bundler', availableBundlers[0])
|
|
576
579
|
.choices('from', fromKeys)
|
|
577
580
|
.describe('from', 'Sets the type of the source to use for publishing.')
|
|
578
581
|
.default('from', apps.publishPiletDefaults.from)
|
|
@@ -590,10 +593,12 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
590
593
|
url: args.url as string,
|
|
591
594
|
logLevel: args['log-level'] as LogLevels,
|
|
592
595
|
cert: args['ca-cert'] as string,
|
|
596
|
+
bundlerName: args.bundler as string,
|
|
593
597
|
fresh: args.fresh as boolean,
|
|
594
598
|
from: args.from as PiletPublishSource,
|
|
595
599
|
schemaVersion: args.schema as PiletSchemaVersion,
|
|
596
600
|
fields: args.fields as Record<string, string>,
|
|
601
|
+
_: args,
|
|
597
602
|
});
|
|
598
603
|
},
|
|
599
604
|
},
|
package/src/common/constants.ts
CHANGED
|
@@ -2,6 +2,7 @@ export const defaultRegistry = 'https://registry.npmjs.org/';
|
|
|
2
2
|
export const filesTar = 'files';
|
|
3
3
|
export const filesOnceTar = 'files_once';
|
|
4
4
|
export const piralBaseRoot = 'piral-base/lib/types';
|
|
5
|
+
export const frameworkLibs = ['piral', 'piral-core', 'piral-base'];
|
|
5
6
|
export const entryModuleExtensions = ['.ts', '.tsx', '.js', '.jsx'];
|
|
6
7
|
export const declarationEntryExtensions = ['.html', '.pug', ...entryModuleExtensions];
|
|
7
8
|
export const legacyCoreExternals = [
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DeclOptions, generateDeclaration, createExcludePlugin, Logger } from 'dets';
|
|
2
2
|
import { dirname, basename, resolve, extname } from 'path';
|
|
3
3
|
import { progress, log, logWarn, logVerbose, logInfo } from './log';
|
|
4
|
-
import { makeExternals } from './npm';
|
|
5
4
|
import { ForceOverwrite } from './enums';
|
|
6
5
|
import { retrievePiralRoot, retrievePiletsInfo } from './package';
|
|
7
6
|
import { entryModuleExtensions, piralBaseRoot } from './constants';
|
|
@@ -132,7 +131,6 @@ export async function createPiralDeclaration(
|
|
|
132
131
|
progress('Reading configuration ...');
|
|
133
132
|
const entryFiles = await retrievePiralRoot(baseDir, entry);
|
|
134
133
|
const { name, root, externals } = await retrievePiletsInfo(entryFiles);
|
|
135
|
-
const allowedImports = makeExternals(externals);
|
|
136
134
|
const entryModules = await getEntryModules(entryFiles);
|
|
137
135
|
const files = await getAllFiles(entryModules);
|
|
138
136
|
const options: DeclOptions = {
|
|
@@ -146,7 +144,7 @@ export async function createPiralDeclaration(
|
|
|
146
144
|
name: 'PiletApi',
|
|
147
145
|
},
|
|
148
146
|
],
|
|
149
|
-
imports:
|
|
147
|
+
imports: externals,
|
|
150
148
|
logLevel,
|
|
151
149
|
logger: createLogger(),
|
|
152
150
|
};
|
package/src/common/emulator.ts
CHANGED
|
@@ -27,7 +27,11 @@ export async function createEmulatorSources(
|
|
|
27
27
|
) {
|
|
28
28
|
const piralPkg = require(resolve(sourceDir, packageJson));
|
|
29
29
|
const files: Array<string | TemplateFileLocation> = piralPkg.pilets?.files ?? [];
|
|
30
|
-
const
|
|
30
|
+
const allDeps = {
|
|
31
|
+
...piralPkg.devDependencies,
|
|
32
|
+
...piralPkg.dependencies,
|
|
33
|
+
};
|
|
34
|
+
const allExternals = makeExternals(allDeps, piralPkg.pilets?.externals);
|
|
31
35
|
|
|
32
36
|
const externalPackages = await Promise.all(
|
|
33
37
|
allExternals.filter(isValidDependency).map(async (name) => ({
|
|
@@ -79,8 +83,7 @@ export async function createEmulatorSources(
|
|
|
79
83
|
app: `./${appDir}/index.html`,
|
|
80
84
|
peerDependencies: {},
|
|
81
85
|
devDependencies: {
|
|
82
|
-
...
|
|
83
|
-
...piralPkg.dependencies,
|
|
86
|
+
...allDeps,
|
|
84
87
|
...externalDependencies,
|
|
85
88
|
},
|
|
86
89
|
sharedDependencies: allExternals,
|
package/src/common/envs.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { log } from './log';
|
|
3
|
+
import { frameworkLibs } from './constants';
|
|
3
4
|
import { pathSeparator, cliVersion, compatVersion } from './info';
|
|
4
5
|
import { StandardEnvProps } from '../types';
|
|
5
6
|
|
|
@@ -43,7 +44,7 @@ export function setStandardEnvs(options: StandardEnvProps) {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
if (options.dependencies && options.dependencies.length) {
|
|
46
|
-
const excludedDependencies = [
|
|
47
|
+
const excludedDependencies = [...frameworkLibs, options.piral];
|
|
47
48
|
const dependencies = options.dependencies.filter((m) => !excludedDependencies.includes(m));
|
|
48
49
|
process.env.SHARED_DEPENDENCIES = dependencies.join(',');
|
|
49
50
|
} else {
|
package/src/common/io.ts
CHANGED
|
@@ -420,10 +420,20 @@ export async function copy(source: string, target: string, forceOverwrite = Forc
|
|
|
420
420
|
|
|
421
421
|
try {
|
|
422
422
|
const flag = forceOverwrite === ForceOverwrite.yes ? 0 : constants.COPYFILE_EXCL;
|
|
423
|
-
await
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
423
|
+
const isDir = await checkIsDirectory(source);
|
|
424
|
+
|
|
425
|
+
if (isDir) {
|
|
426
|
+
const files = await getFileNames(source);
|
|
427
|
+
const results = await Promise.all(
|
|
428
|
+
files.map((file) => copy(resolve(source, file), resolve(target, file), forceOverwrite)),
|
|
429
|
+
);
|
|
430
|
+
return results.every(Boolean);
|
|
431
|
+
} else {
|
|
432
|
+
await new Promise<void>((resolve, reject) => {
|
|
433
|
+
copyFile(source, target, flag, (err) => (err ? reject(err) : resolve()));
|
|
434
|
+
});
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
427
437
|
} catch (e) {
|
|
428
438
|
if (forceOverwrite === ForceOverwrite.prompt) {
|
|
429
439
|
const shouldOverwrite = await promptOverwrite(target);
|
package/src/common/npm.test.ts
CHANGED
|
@@ -407,7 +407,7 @@ describe('npm Module', () => {
|
|
|
407
407
|
});
|
|
408
408
|
|
|
409
409
|
it('makeExternals without externals returns coreExternals', () => {
|
|
410
|
-
const externals = makeExternals();
|
|
410
|
+
const externals = makeExternals({ piral: '*' });
|
|
411
411
|
expect(externals).toEqual([
|
|
412
412
|
'react',
|
|
413
413
|
'react-dom',
|
|
@@ -422,7 +422,7 @@ describe('npm Module', () => {
|
|
|
422
422
|
});
|
|
423
423
|
|
|
424
424
|
it('makeExternals with no externals returns coreExternals', () => {
|
|
425
|
-
const externals = makeExternals([]);
|
|
425
|
+
const externals = makeExternals({ piral: '*' }, []);
|
|
426
426
|
expect(externals).toEqual([
|
|
427
427
|
'react',
|
|
428
428
|
'react-dom',
|
|
@@ -437,12 +437,12 @@ describe('npm Module', () => {
|
|
|
437
437
|
});
|
|
438
438
|
|
|
439
439
|
it('makeExternals with exclude coreExternals returns empty set', () => {
|
|
440
|
-
const externals = makeExternals(['!*']);
|
|
440
|
+
const externals = makeExternals({ piral: '*' }, ['!*']);
|
|
441
441
|
expect(externals).toEqual([]);
|
|
442
442
|
});
|
|
443
443
|
|
|
444
444
|
it('makeExternals with externals concats coreExternals', () => {
|
|
445
|
-
const externals = makeExternals(['foo', 'bar']);
|
|
445
|
+
const externals = makeExternals({ piral: '*' }, ['foo', 'bar']);
|
|
446
446
|
expect(externals).toEqual([
|
|
447
447
|
'foo',
|
|
448
448
|
'bar',
|
|
@@ -459,7 +459,7 @@ describe('npm Module', () => {
|
|
|
459
459
|
});
|
|
460
460
|
|
|
461
461
|
it('makeExternals with external duplicate only reflects coreExternals', () => {
|
|
462
|
-
const externals = makeExternals(['react', 'foo']);
|
|
462
|
+
const externals = makeExternals({ piral: '*' }, ['react', 'foo']);
|
|
463
463
|
expect(externals).toEqual([
|
|
464
464
|
'react',
|
|
465
465
|
'foo',
|
|
@@ -475,7 +475,7 @@ describe('npm Module', () => {
|
|
|
475
475
|
});
|
|
476
476
|
|
|
477
477
|
it('makeExternals with explicit include and exclude', () => {
|
|
478
|
-
const externals = makeExternals(['react', 'react-calendar', '!history']);
|
|
478
|
+
const externals = makeExternals({ piral: '*' }, ['react', 'react-calendar', '!history']);
|
|
479
479
|
expect(externals).toEqual([
|
|
480
480
|
'react',
|
|
481
481
|
'react-calendar',
|
|
@@ -490,7 +490,7 @@ describe('npm Module', () => {
|
|
|
490
490
|
});
|
|
491
491
|
|
|
492
492
|
it('makeExternals with all exclude and explicit include', () => {
|
|
493
|
-
const externals = makeExternals(['react', 'react-router-dom', '!*']);
|
|
493
|
+
const externals = makeExternals({ piral: '*' }, ['react', 'react-router-dom', '!*']);
|
|
494
494
|
expect(externals).toEqual(['react', 'react-router-dom']);
|
|
495
495
|
});
|
|
496
496
|
});
|
package/src/common/npm.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { inspectPackage } from './inspect';
|
|
|
7
7
|
import { readJson, checkExists, findFile } from './io';
|
|
8
8
|
import { clientTypeKeys } from '../helpers';
|
|
9
9
|
import { PackageType, NpmClientType } from '../types';
|
|
10
|
+
import { frameworkLibs } from '.';
|
|
10
11
|
|
|
11
12
|
const gitPrefix = 'git+';
|
|
12
13
|
const filePrefix = 'file:';
|
|
@@ -421,25 +422,44 @@ export function getPackageVersion(
|
|
|
421
422
|
}
|
|
422
423
|
}
|
|
423
424
|
|
|
424
|
-
|
|
425
|
+
function getExternalsFrom(packageName: string): Array<string> | undefined {
|
|
425
426
|
try {
|
|
426
|
-
return require(
|
|
427
|
+
return require(`${packageName}/package.json`).sharedDependencies;
|
|
427
428
|
} catch {
|
|
428
|
-
return
|
|
429
|
+
return undefined;
|
|
429
430
|
}
|
|
430
431
|
}
|
|
431
432
|
|
|
432
|
-
|
|
433
|
+
function getCoreExternals(dependencies: Record<string, string>): Array<string> {
|
|
434
|
+
for (const frameworkLib of frameworkLibs) {
|
|
435
|
+
if (dependencies[frameworkLib]) {
|
|
436
|
+
const deps = getExternalsFrom(frameworkLib);
|
|
437
|
+
|
|
438
|
+
if (deps) {
|
|
439
|
+
return deps;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return [];
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export function makePiletExternals(
|
|
448
|
+
dependencies: Record<string, string>,
|
|
449
|
+
externals: Array<string>,
|
|
450
|
+
fromEmulator: boolean,
|
|
451
|
+
piralInfo: any,
|
|
452
|
+
) {
|
|
433
453
|
if (fromEmulator) {
|
|
434
|
-
const { sharedDependencies = makeExternals(externals, true) } = piralInfo;
|
|
454
|
+
const { sharedDependencies = makeExternals(dependencies, externals, true) } = piralInfo;
|
|
435
455
|
return sharedDependencies;
|
|
436
456
|
} else {
|
|
437
|
-
return makeExternals(externals);
|
|
457
|
+
return makeExternals(dependencies, externals);
|
|
438
458
|
}
|
|
439
459
|
}
|
|
440
460
|
|
|
441
|
-
export function makeExternals(externals?: Array<string>, legacy = false) {
|
|
442
|
-
const coreExternals = legacy ? legacyCoreExternals : getCoreExternals();
|
|
461
|
+
export function makeExternals(dependencies: Record<string, string>, externals?: Array<string>, legacy = false) {
|
|
462
|
+
const coreExternals = legacy ? legacyCoreExternals : getCoreExternals(dependencies);
|
|
443
463
|
|
|
444
464
|
if (externals && Array.isArray(externals)) {
|
|
445
465
|
const [include, exclude] = externals.reduce<[Array<string>, Array<string>]>(
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
|
-
import {
|
|
3
|
-
findPackageVersion,
|
|
4
|
-
findPackageRoot,
|
|
5
|
-
getPiralPackage,
|
|
6
|
-
getPiletsInfo,
|
|
7
|
-
retrievePiletData,
|
|
8
|
-
} from './package';
|
|
2
|
+
import { findPackageVersion, findPackageRoot, getPiralPackage, getPiletsInfo, retrievePiletData } from './package';
|
|
9
3
|
import { cliVersion } from './info';
|
|
10
4
|
import { SourceLanguage } from './enums';
|
|
11
5
|
|
package/src/common/package.ts
CHANGED
|
@@ -442,8 +442,12 @@ export async function retrievePiletsInfo(entryFile: string) {
|
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
const packageInfo = require(packageJson);
|
|
445
|
+
const allDeps = {
|
|
446
|
+
...packageInfo.devDependencies,
|
|
447
|
+
...packageInfo.dependencies,
|
|
448
|
+
};
|
|
445
449
|
const info = getPiletsInfo(packageInfo);
|
|
446
|
-
const externals = makeExternals(info.externals);
|
|
450
|
+
const externals = makeExternals(allDeps, info.externals);
|
|
447
451
|
|
|
448
452
|
return {
|
|
449
453
|
...info,
|
|
@@ -495,7 +499,7 @@ export async function patchPiletPackage(
|
|
|
495
499
|
}
|
|
496
500
|
: info.scripts;
|
|
497
501
|
const peerModules = [];
|
|
498
|
-
const allExternals = makePiletExternals(externals, fromEmulator, piralInfo);
|
|
502
|
+
const allExternals = makePiletExternals(piralDependencies, externals, fromEmulator, piralInfo);
|
|
499
503
|
const peerDependencies = {
|
|
500
504
|
...allExternals.reduce((deps, name) => {
|
|
501
505
|
const valid = isValidDependency(name);
|
package/src/helpers.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
export const schemaKeys: Array<PiletSchemaVersion> = ['v0', 'v1', 'v2', 'none'];
|
|
12
12
|
export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
|
|
13
13
|
export const piralBuildTypeKeys: Array<PiralBuildType> = ['all', 'release', 'emulator', 'emulator-sources'];
|
|
14
|
-
export const piletBuildTypeKeys: Array<PiletBuildType> = ['default', 'standalone'];
|
|
14
|
+
export const piletBuildTypeKeys: Array<PiletBuildType> = ['default', 'standalone', 'manifest'];
|
|
15
15
|
export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'yarn'];
|
|
16
16
|
export const bundlerKeys: Array<string> = ['none', 'parcel', 'webpack', 'webpack5', 'esbuild'];
|
|
17
17
|
export const availableBundlers: Array<string> = [];
|
package/src/types/public.ts
CHANGED
|
@@ -85,6 +85,7 @@ export interface WatchPiralParameters extends BaseBundleParameters {
|
|
|
85
85
|
export interface BuildPiralParameters extends BaseBundleParameters {
|
|
86
86
|
piral: string;
|
|
87
87
|
emulator: boolean;
|
|
88
|
+
standalone: boolean;
|
|
88
89
|
sourceMaps: boolean;
|
|
89
90
|
contentHash: boolean;
|
|
90
91
|
minify: boolean;
|
|
@@ -217,7 +218,7 @@ export type PiletPublishSource = 'local' | 'npm' | 'remote';
|
|
|
217
218
|
|
|
218
219
|
export type PiralBuildType = 'all' | 'release' | 'emulator' | 'emulator-sources';
|
|
219
220
|
|
|
220
|
-
export type PiletBuildType = 'default' | 'standalone';
|
|
221
|
+
export type PiletBuildType = 'default' | 'standalone' | 'manifest';
|
|
221
222
|
|
|
222
223
|
export type PackageType = 'registry' | 'file' | 'git';
|
|
223
224
|
|