publish-microfrontend 0.15.9-beta.5387 → 0.15.9-beta.5415

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 (3) hide show
  1. package/lib/index.js +29 -10
  2. package/package.json +2 -2
  3. package/src/utils.ts +40 -12
package/lib/index.js CHANGED
@@ -26580,6 +26580,7 @@ var bundlerNames = [
26580
26580
  "parcel",
26581
26581
  "parcel2",
26582
26582
  "rollup",
26583
+ "rspack",
26583
26584
  "webpack",
26584
26585
  "webpack5",
26585
26586
  "vite",
@@ -27385,9 +27386,15 @@ function onlyUnique(value, index, self) {
27385
27386
  return self.indexOf(value) === index;
27386
27387
  }
27387
27388
  function isFile(item) {
27389
+ if (!item || typeof item !== "string") {
27390
+ return false;
27391
+ }
27388
27392
  return (0, import_fs2.statSync)(item).isFile();
27389
27393
  }
27390
27394
  function isDirectory(item) {
27395
+ if (!item || typeof item !== "string") {
27396
+ return false;
27397
+ }
27391
27398
  return (0, import_fs2.statSync)(item).isDirectory();
27392
27399
  }
27393
27400
  function matchFiles(baseDir, pattern) {
@@ -27426,17 +27433,29 @@ function getFiles(baseDir, sources, from, ca) {
27426
27433
  const allMatches = allFiles.reduce((result, files) => [...result, ...files], []).filter(onlyUnique);
27427
27434
  if (allMatches.every(isDirectory)) {
27428
27435
  const dirs = allMatches.filter((m) => (0, import_fs2.existsSync)((0, import_path3.resolve)(m, "package.json")));
27429
- return Promise.all(dirs.map((dir) => __async(this, null, function* () {
27430
- const previousFiles = yield (0, import_promises.readdir)(dir);
27431
- yield createPackage(dir);
27432
- const currentFiles = yield (0, import_promises.readdir)(dir);
27433
- const tarball = currentFiles.find((m) => !previousFiles.includes(m) && m.endsWith(".tgz"));
27434
- const target = getRandomTempFile();
27435
- const source = (0, import_path3.resolve)(dir, tarball);
27436
- yield (0, import_promises.copyFile)(source, target);
27437
- yield (0, import_promises.rm)(source);
27438
- return target;
27436
+ const createdFiles = yield Promise.all(dirs.map((dir) => __async(this, null, function* () {
27437
+ const packagePath = (0, import_path3.resolve)(dir, "package.json");
27438
+ const packageContent = yield (0, import_promises.readFile)(packagePath, "utf8");
27439
+ try {
27440
+ const { name, version } = JSON.parse(packageContent);
27441
+ const proposedName = `${name.replace("@", "").replace("/", "-")}-${version}.tgz`;
27442
+ const previousFiles = yield (0, import_promises.readdir)(dir);
27443
+ if (previousFiles.includes(proposedName)) {
27444
+ return (0, import_path3.resolve)(dir, proposedName);
27445
+ }
27446
+ yield createPackage(dir);
27447
+ const currentFiles = yield (0, import_promises.readdir)(dir);
27448
+ const tarball = currentFiles.find((m) => !previousFiles.includes(m) && m.endsWith(".tgz"));
27449
+ const target = getRandomTempFile();
27450
+ const source = (0, import_path3.resolve)(dir, tarball);
27451
+ yield (0, import_promises.copyFile)(source, target);
27452
+ yield (0, import_promises.rm)(source);
27453
+ return target;
27454
+ } catch (e) {
27455
+ logWarn('Encountered error in "%s". Skipping.', dir);
27456
+ }
27439
27457
  })));
27458
+ return createdFiles.filter(isFile);
27440
27459
  }
27441
27460
  return allMatches.filter(isFile);
27442
27461
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "publish-microfrontend",
3
- "version": "0.15.9-beta.5387",
3
+ "version": "0.15.9-beta.5415",
4
4
  "description": "A CLI for publishing micro frontends to a feed service.",
5
5
  "keywords": [
6
6
  "modules",
@@ -69,5 +69,5 @@
69
69
  "typescript": "^4.0.0",
70
70
  "yargs": "^15.0.0"
71
71
  },
72
- "gitHead": "7e8a09cd29f25a8986169bad38e270b95be0059a"
72
+ "gitHead": "85149fa812581dc049a38da51944099330f332db"
73
73
  }
package/src/utils.ts CHANGED
@@ -5,6 +5,7 @@ import { dirname, basename, resolve } from 'path';
5
5
  import { MemoryStream } from 'piral-cli/src/common/MemoryStream';
6
6
  import { downloadFile } from './http';
7
7
  import { runCommand } from './scripts';
8
+ import { logWarn } from './log';
8
9
  import { getRandomTempFile } from './io';
9
10
 
10
11
  function runNpmProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
@@ -29,10 +30,18 @@ function onlyUnique<T>(value: T, index: number, self: Array<T>) {
29
30
  }
30
31
 
31
32
  function isFile(item: string) {
33
+ if (!item || typeof item !== 'string') {
34
+ return false;
35
+ }
36
+
32
37
  return statSync(item).isFile();
33
38
  }
34
39
 
35
40
  function isDirectory(item: string) {
41
+ if (!item || typeof item !== 'string') {
42
+ return false;
43
+ }
44
+
36
45
  return statSync(item).isDirectory();
37
46
  }
38
47
 
@@ -82,18 +91,37 @@ export async function getFiles(
82
91
  const allMatches = allFiles.reduce((result, files) => [...result, ...files], []).filter(onlyUnique);
83
92
 
84
93
  if (allMatches.every(isDirectory)) {
85
- const dirs = allMatches.filter(m => existsSync(resolve(m, 'package.json')));
86
- return Promise.all(dirs.map(async dir => {
87
- const previousFiles = await readdir(dir);
88
- await createPackage(dir);
89
- const currentFiles = await readdir(dir);
90
- const tarball = currentFiles.find(m => !previousFiles.includes(m) && m.endsWith('.tgz'));
91
- const target = getRandomTempFile();
92
- const source = resolve(dir, tarball);
93
- await copyFile(source, target);
94
- await rm(source);
95
- return target;
96
- }));
94
+ const dirs = allMatches.filter((m) => existsSync(resolve(m, 'package.json')));
95
+ const createdFiles = await Promise.all(
96
+ dirs.map(async (dir) => {
97
+ const packagePath = resolve(dir, 'package.json');
98
+ const packageContent = await readFile(packagePath, 'utf8');
99
+
100
+ try {
101
+ const { name, version } = JSON.parse(packageContent);
102
+ const proposedName = `${name.replace('@', '').replace('/', '-')}-${version}.tgz`;
103
+ const previousFiles = await readdir(dir);
104
+
105
+ // what if previousFiles contains already an npm package with the name ... "<name>-<version>.tgz" ?
106
+ // do not pack package; use this one instead.
107
+ if (previousFiles.includes(proposedName)) {
108
+ return resolve(dir, proposedName);
109
+ }
110
+
111
+ await createPackage(dir);
112
+ const currentFiles = await readdir(dir);
113
+ const tarball = currentFiles.find((m) => !previousFiles.includes(m) && m.endsWith('.tgz'));
114
+ const target = getRandomTempFile();
115
+ const source = resolve(dir, tarball);
116
+ await copyFile(source, target);
117
+ await rm(source);
118
+ return target;
119
+ } catch {
120
+ logWarn('Encountered error in "%s". Skipping.', dir);
121
+ }
122
+ }),
123
+ );
124
+ return createdFiles.filter(isFile);
97
125
  }
98
126
 
99
127
  return allMatches.filter(isFile);