piral-cli 1.3.3-beta.6190 → 1.3.3-beta.6204

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.
Files changed (99) hide show
  1. package/lib/apps/build-pilet.js +1 -1
  2. package/lib/apps/build-pilet.js.map +1 -1
  3. package/lib/bundler.js +25 -1
  4. package/lib/bundler.js.map +1 -1
  5. package/lib/cli.js +5 -2
  6. package/lib/cli.js.map +1 -1
  7. package/lib/commands.js +24 -1
  8. package/lib/commands.js.map +1 -1
  9. package/lib/common/declaration.d.ts +1 -1
  10. package/lib/common/declaration.js +43 -18
  11. package/lib/common/declaration.js.map +1 -1
  12. package/lib/common/io.js +5 -2
  13. package/lib/common/io.js.map +1 -1
  14. package/lib/common/log.js +24 -1
  15. package/lib/common/log.js.map +1 -1
  16. package/lib/common/npm.js +13 -13
  17. package/lib/common/npm.js.map +1 -1
  18. package/lib/external/index.js +426 -230
  19. package/lib/inject.js +24 -1
  20. package/lib/inject.js.map +1 -1
  21. package/lib/{common/clients → npm-clients}/bun.js +5 -5
  22. package/lib/npm-clients/bun.js.map +1 -0
  23. package/lib/{common/clients → npm-clients}/index.js +31 -8
  24. package/lib/npm-clients/index.js.map +1 -0
  25. package/lib/{common/clients → npm-clients}/lerna.js +4 -4
  26. package/lib/npm-clients/lerna.js.map +1 -0
  27. package/lib/{common/clients → npm-clients}/npm.js +4 -4
  28. package/lib/npm-clients/npm.js.map +1 -0
  29. package/lib/{common/clients → npm-clients}/pnp.js +4 -4
  30. package/lib/npm-clients/pnp.js.map +1 -0
  31. package/lib/{common/clients → npm-clients}/pnpm.js +4 -4
  32. package/lib/npm-clients/pnpm.js.map +1 -0
  33. package/lib/{common/clients → npm-clients}/rush.js +5 -5
  34. package/lib/npm-clients/rush.js.map +1 -0
  35. package/lib/{common/clients → npm-clients}/yarn.js +4 -4
  36. package/lib/npm-clients/yarn.js.map +1 -0
  37. package/package.json +3 -3
  38. package/src/apps/build-pilet.test.ts +1 -0
  39. package/src/apps/build-pilet.ts +1 -0
  40. package/src/apps/build-piral.test.ts +19 -12
  41. package/src/apps/new-pilet.test.ts +120 -76
  42. package/src/apps/new-piral.test.ts +100 -77
  43. package/src/apps/pack-pilet.test.ts +2 -3
  44. package/src/apps/upgrade-pilet.test.ts +1 -0
  45. package/src/bundler.test.ts +8 -7
  46. package/src/bundler.ts +2 -1
  47. package/src/cli.ts +1 -1
  48. package/src/common/archive.test.ts +10 -7
  49. package/src/common/browser.test.ts +2 -1
  50. package/src/common/compatibility.test.ts +1 -0
  51. package/src/common/declaration.ts +49 -20
  52. package/src/common/envs.test.ts +2 -1
  53. package/src/common/hash.test.ts +1 -0
  54. package/src/common/http.test.ts +73 -70
  55. package/src/common/importmap.test.ts +3 -2
  56. package/src/common/info.test.ts +1 -0
  57. package/src/common/interactive.test.ts +2 -1
  58. package/src/common/io.ts +1 -1
  59. package/src/common/merge.test.ts +1 -0
  60. package/src/common/npm.test.ts +35 -37
  61. package/src/common/npm.ts +1 -1
  62. package/src/common/pack.test.ts +11 -10
  63. package/src/common/package.test.ts +131 -92
  64. package/src/common/parallel.test.ts +1 -0
  65. package/src/common/patches.test.ts +1 -0
  66. package/src/common/port.test.ts +2 -1
  67. package/src/common/rules.test.ts +4 -3
  68. package/src/common/url.test.ts +1 -0
  69. package/src/common/utils.test.ts +1 -0
  70. package/src/common/version.test.ts +1 -0
  71. package/src/external/index.test.ts +1 -0
  72. package/src/helpers.test.ts +1 -0
  73. package/src/injectors/pilet-injector.test.ts +6 -5
  74. package/src/injectors/piral-injector.test.ts +7 -6
  75. package/src/{common/clients → npm-clients}/bun.ts +5 -5
  76. package/src/{common/clients → npm-clients}/index.ts +1 -1
  77. package/src/{common/clients → npm-clients}/lerna.ts +4 -4
  78. package/src/{common/clients → npm-clients}/npm.ts +4 -4
  79. package/src/{common/clients → npm-clients}/pnp.ts +4 -4
  80. package/src/{common/clients → npm-clients}/pnpm.ts +4 -4
  81. package/src/{common/clients → npm-clients}/rush.ts +5 -5
  82. package/src/{common/clients → npm-clients}/yarn.ts +4 -4
  83. package/src/rules/pilet-has-externals-as-peers.test.ts +4 -3
  84. package/lib/common/clients/bun.js.map +0 -1
  85. package/lib/common/clients/index.js.map +0 -1
  86. package/lib/common/clients/lerna.js.map +0 -1
  87. package/lib/common/clients/npm.js.map +0 -1
  88. package/lib/common/clients/pnp.js.map +0 -1
  89. package/lib/common/clients/pnpm.js.map +0 -1
  90. package/lib/common/clients/rush.js.map +0 -1
  91. package/lib/common/clients/yarn.js.map +0 -1
  92. /package/lib/{common/clients → npm-clients}/bun.d.ts +0 -0
  93. /package/lib/{common/clients → npm-clients}/index.d.ts +0 -0
  94. /package/lib/{common/clients → npm-clients}/lerna.d.ts +0 -0
  95. /package/lib/{common/clients → npm-clients}/npm.d.ts +0 -0
  96. /package/lib/{common/clients → npm-clients}/pnp.d.ts +0 -0
  97. /package/lib/{common/clients → npm-clients}/pnpm.d.ts +0 -0
  98. /package/lib/{common/clients → npm-clients}/rush.d.ts +0 -0
  99. /package/lib/{common/clients → npm-clients}/yarn.d.ts +0 -0
@@ -1,13 +1,15 @@
1
- import { DeclOptions, generateDeclaration, createExcludePlugin, Logger } from 'dets';
1
+ import { DeclOptions, generateDeclaration, createDiffPlugin, Logger } from 'dets';
2
2
  import { dirname, basename, resolve, extname } from 'path';
3
3
  import { progress, log, logWarn, logVerbose, logInfo } from './log';
4
4
  import { ForceOverwrite } from './enums';
5
5
  import { retrievePiralRoot, retrievePiletsInfo, flattenExternals, validateSharedDependencies } from './package';
6
- import { entryModuleExtensions, piralBaseRoot } from './constants';
7
- import { readText, getEntryFiles, matchFiles, createFileIfNotExists } from './io';
6
+ import { entryModuleExtensions, piralBaseRoot, packageJson } from './constants';
7
+ import { readText, getEntryFiles, matchFiles, createFileIfNotExists, readJson } from './io';
8
8
  import { getModulePath } from '../external';
9
9
  import { LogLevels } from '../types';
10
10
 
11
+ const piletApiName = 'PiletApi';
12
+
11
13
  function findPiralBaseRoot(root: string, framework: string) {
12
14
  const piralJson = `${framework}/package.json`;
13
15
 
@@ -21,6 +23,26 @@ function findPiralBaseRoot(root: string, framework: string) {
21
23
  return root;
22
24
  }
23
25
 
26
+ async function findPiralInstanceApi(piralInstance: string) {
27
+ if (piralInstance) {
28
+ const path = require.resolve(`${piralInstance}/${packageJson}`);
29
+ const root = dirname(path);
30
+ const data = await readJson(root, packageJson);
31
+ const subpath = data.types || data.typings;
32
+
33
+ if (subpath) {
34
+ return [
35
+ {
36
+ file: resolve(root, subpath),
37
+ name: piletApiName,
38
+ },
39
+ ];
40
+ }
41
+ }
42
+
43
+ return [];
44
+ }
45
+
24
46
  function findPiralBaseApi(root: string, framework: string) {
25
47
  // for some package managers, e.g., pnpm we need to first go into
26
48
  // some specifics before being able to retrieve "piral-base"
@@ -36,7 +58,7 @@ function findPiralBaseApi(root: string, framework: string) {
36
58
  return [
37
59
  {
38
60
  file: resolve(projectDir, piletApiTypings),
39
- name: 'PiletApi',
61
+ name: piletApiName,
40
62
  },
41
63
  ];
42
64
  } catch (err) {
@@ -113,7 +135,7 @@ async function createDeclarationFile(
113
135
  progress('Bundling declaration file ...');
114
136
 
115
137
  try {
116
- const result = generateDeclaration(options);
138
+ const result = await generateDeclaration(options);
117
139
 
118
140
  progress('Writing declaration file ...');
119
141
  await createFileIfNotExists(target, 'index.d.ts', result, forceOverwrite);
@@ -124,6 +146,7 @@ async function createDeclarationFile(
124
146
 
125
147
  export async function createPiletDeclaration(
126
148
  name: string,
149
+ piralInstances: Array<string>,
127
150
  root: string,
128
151
  entry: string,
129
152
  allowedImports: Array<string>,
@@ -131,21 +154,27 @@ export async function createPiletDeclaration(
131
154
  forceOverwrite: ForceOverwrite,
132
155
  logLevel: LogLevels,
133
156
  ) {
134
- const files = await getAllFiles([entry]);
135
- const types = findDeclaredTypings(root);
136
- const options: DeclOptions = {
137
- name,
138
- root,
139
- files,
140
- types: [...types, ...files],
141
- plugins: [createExcludePlugin([name])],
142
- apis: [],
143
- noModuleDeclaration: true,
144
- imports: allowedImports,
145
- logLevel,
146
- logger: createLogger(),
147
- };
148
- return await createDeclarationFile(options, root, target, forceOverwrite);
157
+ const piralInstance = piralInstances[0];
158
+ const apis = await findPiralInstanceApi(piralInstance);
159
+ const file = apis.map((m) => m.file)[0];
160
+
161
+ if (file) {
162
+ const files = await getAllFiles([entry]);
163
+ const types = findDeclaredTypings(root);
164
+ const options: DeclOptions = {
165
+ name: piralInstance,
166
+ root,
167
+ files,
168
+ types,
169
+ plugins: [createDiffPlugin(file)],
170
+ apis,
171
+ noModuleDeclaration: true,
172
+ imports: allowedImports,
173
+ logLevel,
174
+ logger: createLogger(),
175
+ };
176
+ return await createDeclarationFile(options, root, target, forceOverwrite);
177
+ }
149
178
  }
150
179
 
151
180
  export async function createPiralDeclaration(
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect, vitest, beforeEach, afterEach } from 'vitest';
1
2
  import { resolve } from 'path';
2
3
  import { setStandardEnvs } from './envs';
3
4
 
@@ -7,7 +8,7 @@ describe('Environment Module', () => {
7
8
  const oldEnv = process.env;
8
9
 
9
10
  beforeEach(() => {
10
- jest.resetModules();
11
+ vitest.resetModules();
11
12
  process.env = {};
12
13
  });
13
14
 
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import { computeHash, computeMd5 } from './hash';
2
3
 
3
4
  describe('Hash Module', () => {
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { postFile, downloadFile } from './http';
2
3
 
3
4
  const apiUrl = 'http://sample.fooo.com/api/v1/pilet';
@@ -7,79 +8,81 @@ let errorOther = false;
7
8
  let errorResponse = false;
8
9
  let errorResponse2 = false;
9
10
 
10
- jest.mock('../external', () => ({
11
- rc(_, cfg) {
12
- return cfg;
13
- },
14
- ora() {
15
- return {
16
- warn() {},
17
- fail() {},
18
- };
19
- },
20
- axios: {
21
- default: {
22
- post(url, _, options) {
23
- const found = url === apiUrl;
24
- const auth = options.headers.authorization === 'Basic 123';
11
+ vitest.mock('../external', async () => {
12
+ return {
13
+ rc(_, cfg) {
14
+ return cfg;
15
+ },
16
+ ora() {
17
+ return {
18
+ warn() {},
19
+ fail() {},
20
+ };
21
+ },
22
+ axios: {
23
+ default: {
24
+ post(url, _, options) {
25
+ const found = url === apiUrl;
26
+ const auth = options.headers.authorization === 'Basic 123';
25
27
 
26
- if (errorRequest) {
27
- return Promise.reject({
28
- request: {},
29
- });
30
- } else if (errorOther) {
31
- return Promise.reject({
32
- message: 'error',
33
- });
34
- } else if (errorResponse) {
35
- return Promise.reject({
36
- response: {
37
- status: 410,
38
- statusText: 'Not Gone',
39
- data: '{ "message": "This component is not available anymore." }',
40
- },
41
- });
42
- } else if (errorResponse2) {
43
- return Promise.reject({
44
- response: {
45
- status: 410,
46
- statusText: 'Not Gone',
47
- data: { message: 'This component is not available anymore.' },
48
- },
49
- });
50
- } else if (!found) {
51
- return Promise.reject({
52
- response: {
53
- status: 404,
54
- statusText: 'Not found',
55
- },
56
- });
57
- } else if (!auth) {
58
- return Promise.reject({
59
- response: {
60
- status: 401,
61
- statusText: 'Not authorized',
62
- },
63
- });
64
- } else {
65
- return Promise.resolve({
66
- status: 200,
67
- statusText: 'OK',
68
- });
69
- }
70
- },
71
- get(url, options) {
72
- if (errorOther) {
73
- return Promise.reject({
74
- message: 'error',
75
- });
76
- }
77
- return Promise.resolve({ data: 'test' });
28
+ if (errorRequest) {
29
+ return Promise.reject({
30
+ request: {},
31
+ });
32
+ } else if (errorOther) {
33
+ return Promise.reject({
34
+ message: 'error',
35
+ });
36
+ } else if (errorResponse) {
37
+ return Promise.reject({
38
+ response: {
39
+ status: 410,
40
+ statusText: 'Not Gone',
41
+ data: '{ "message": "This component is not available anymore." }',
42
+ },
43
+ });
44
+ } else if (errorResponse2) {
45
+ return Promise.reject({
46
+ response: {
47
+ status: 410,
48
+ statusText: 'Not Gone',
49
+ data: { message: 'This component is not available anymore.' },
50
+ },
51
+ });
52
+ } else if (!found) {
53
+ return Promise.reject({
54
+ response: {
55
+ status: 404,
56
+ statusText: 'Not found',
57
+ },
58
+ });
59
+ } else if (!auth) {
60
+ return Promise.reject({
61
+ response: {
62
+ status: 401,
63
+ statusText: 'Not authorized',
64
+ },
65
+ });
66
+ } else {
67
+ return Promise.resolve({
68
+ status: 200,
69
+ statusText: 'OK',
70
+ });
71
+ }
72
+ },
73
+ get(url, options) {
74
+ if (errorOther) {
75
+ return Promise.reject({
76
+ message: 'error',
77
+ });
78
+ }
79
+ return Promise.resolve({ data: 'test' });
80
+ },
78
81
  },
79
82
  },
80
- },
81
- FormData: jest.requireActual('form-data'),
82
- }));
83
+ FormData: (await vitest.importActual('form-data') as any).default,
84
+ };
85
+ });
83
86
 
84
87
  describe('HTTP Module', () => {
85
88
  it('postFile form posts a file successfully should be ok', async () => {
@@ -1,6 +1,7 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { readImportmap } from './importmap';
2
3
 
3
- jest.mock('./npm', () => ({
4
+ vitest.mock('./npm', () => ({
4
5
  tryResolvePackage(id, dir) {
5
6
  if (id === 'qxz') {
6
7
  return undefined;
@@ -45,7 +46,7 @@ const mockPackages = {
45
46
  },
46
47
  };
47
48
 
48
- jest.mock('./io', () => ({
49
+ vitest.mock('./io', () => ({
49
50
  checkIsDirectory() {},
50
51
  getHash() {},
51
52
  readJson(dir) {
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import { findCompatVersion } from './info';
2
3
 
3
4
  describe('CLI info module', () => {
@@ -1,8 +1,9 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { promptConfirm, promptSelect } from './interactive';
2
3
 
3
4
  const answer = 'Yes, really';
4
5
 
5
- jest.mock('../external', () => ({
6
+ vitest.mock('../external', () => ({
6
7
  rc(_, cfg) {
7
8
  return cfg;
8
9
  },
package/src/common/io.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as rimraf from 'rimraf';
1
+ import rimraf from 'rimraf';
2
2
  import { transpileModule, ModuleKind, ModuleResolutionKind, ScriptTarget, JsxEmit } from 'typescript';
3
3
  import { join, resolve, basename, dirname, extname } from 'path';
4
4
  import { exists, lstat, unlink, statSync } from 'fs';
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import { deepMerge } from './merge';
2
3
 
3
4
  describe('Merge Module', () => {
@@ -1,5 +1,6 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { resolve } from 'path';
2
- import { clients } from './clients';
3
+ import { clients } from '../npm-clients';
3
4
  import {
4
5
  dissectPackageName,
5
6
  installNpmPackage,
@@ -24,10 +25,10 @@ import {
24
25
  findPackageRoot,
25
26
  } from './npm';
26
27
 
27
- jest.mock('child_process');
28
+ vitest.mock('child_process');
28
29
 
29
- jest.mock('../external', () => ({
30
- ...jest.requireActual('../external'),
30
+ vitest.mock('../external', async () => ({
31
+ ...((await vitest.importActual('../external')) as any),
31
32
  rc() {},
32
33
  ora() {
33
34
  return {
@@ -58,7 +59,7 @@ let wrongCase = false;
58
59
  const jsonValueString = JSON.stringify([{ name: 'npm' }]);
59
60
  const jsonValueStringWrong = JSON.stringify([]);
60
61
 
61
- jest.mock('./scripts', () => ({
62
+ vitest.mock('./scripts', () => ({
62
63
  runCommand: (exe: string, args: Array<string>, cwd: string, output?: NodeJS.WritableStream) => {
63
64
  return new Promise<void>((resolve) => {
64
65
  output?.write(wrongCase ? jsonValueStringWrong : jsonValueString, () => {});
@@ -67,29 +68,34 @@ jest.mock('./scripts', () => ({
67
68
  },
68
69
  }));
69
70
 
70
- jest.mock('fs', () => ({
71
- ...jest.requireActual('fs'),
72
- exists: (file: string, cb: (status: boolean) => void) =>
73
- cb(
74
- shouldFind &&
75
- !file.endsWith('package.json') &&
76
- !(specialCase && (file.endsWith('lerna.json') || file.endsWith('yarn.lock'))),
77
- ),
78
- existsSync: (file: string) => {
79
- return true;
80
- },
81
- readFile: (file: string, type: string, callback: (err: NodeJS.ErrnoException | undefined, data: string) => void) => {
82
- const fs = jest.requireActual('fs');
83
-
84
- if (fs.existsSync(file)) {
85
- return fs.readFile(file, type, callback);
86
- }
87
-
88
- return callback(undefined, '');
89
- },
90
- realpathSync: () => ({}),
91
- readFileSync: () => '',
92
- }));
71
+ vitest.mock('fs', async () => {
72
+ const fs = (await vitest.importActual('fs')) as any;
73
+ return {
74
+ ...fs,
75
+ exists: (file: string, cb: (status: boolean) => void) =>
76
+ cb(
77
+ shouldFind &&
78
+ !file.endsWith('package.json') &&
79
+ !(specialCase && (file.endsWith('lerna.json') || file.endsWith('yarn.lock'))),
80
+ ),
81
+ existsSync: (file: string) => {
82
+ return true;
83
+ },
84
+ readFile: (
85
+ file: string,
86
+ type: string,
87
+ callback: (err: NodeJS.ErrnoException | undefined, data: string) => void,
88
+ ) => {
89
+ if (fs.existsSync(file)) {
90
+ return fs.readFile(file, type, callback);
91
+ }
92
+
93
+ return callback(undefined, '');
94
+ },
95
+ realpathSync: () => ({}),
96
+ readFileSync: () => '',
97
+ };
98
+ });
93
99
 
94
100
  describe('npm Module', () => {
95
101
  it('findPackageRoot correctly resolves the package root of parcel-bundler', () => {
@@ -488,15 +494,7 @@ describe('npm Module', () => {
488
494
 
489
495
  it('makeExternals with externals concats coreExternals', async () => {
490
496
  const externals = await makeExternals(process.cwd(), { piral: '*' }, ['foo', 'bar']);
491
- expect(externals).toEqual([
492
- 'foo',
493
- 'bar',
494
- 'react',
495
- 'react-dom',
496
- 'react-router',
497
- 'react-router-dom',
498
- 'tslib',
499
- ]);
497
+ expect(externals).toEqual(['foo', 'bar', 'react', 'react-dom', 'react-router', 'react-router-dom', 'tslib']);
500
498
  });
501
499
 
502
500
  it('makeExternals with external duplicate only reflects coreExternals', async () => {
package/src/common/npm.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { resolve, relative, dirname } from 'path';
2
2
  import { createReadStream, existsSync } from 'fs';
3
3
  import { log, fail } from './log';
4
- import { clients, detectClients, isWrapperClient } from './clients';
5
4
  import { config } from './config';
6
5
  import { legacyCoreExternals, frameworkLibs, defaultRegistry, packageJson } from './constants';
7
6
  import { inspectPackage } from './inspect';
8
7
  import { readJson, checkExists } from './io';
8
+ import { clients, detectClients, isWrapperClient } from '../npm-clients';
9
9
  import { clientTypeKeys } from '../helpers';
10
10
  import { getModulePath } from '../external';
11
11
  import { PackageType, NpmClientType } from '../types';
@@ -1,20 +1,21 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { createPiletPackage } from './pack';
2
3
  import { resolve } from 'path';
3
4
 
4
5
  let json: any = {};
5
6
 
6
- jest.mock('./io', () => ({
7
- readJson: jest.fn(() => json),
8
- removeDirectory: jest.fn(() => Promise.resolve()),
9
- checkIsDirectory: jest.fn(() => false),
10
- makeTempDir: jest.fn(() => Promise.resolve('')),
11
- copy: jest.fn(() => Promise.resolve()),
12
- checkExists: jest.fn(() => Promise.resolve(true)),
13
- createDirectory: jest.fn(() => Promise.resolve()),
7
+ vitest.mock('./io', () => ({
8
+ readJson: vitest.fn(() => json),
9
+ removeDirectory: vitest.fn(() => Promise.resolve()),
10
+ checkIsDirectory: vitest.fn(() => false),
11
+ makeTempDir: vitest.fn(() => Promise.resolve('')),
12
+ copy: vitest.fn(() => Promise.resolve()),
13
+ checkExists: vitest.fn(() => Promise.resolve(true)),
14
+ createDirectory: vitest.fn(() => Promise.resolve()),
14
15
  }));
15
16
 
16
- jest.mock('./archive', () => ({
17
- createTgz: jest.fn(() => Promise.resolve()),
17
+ vitest.mock('./archive', () => ({
18
+ createTgz: vitest.fn(() => Promise.resolve()),
18
19
  }));
19
20
 
20
21
  describe('Pack Module', () => {