npm-pkgbuild 8.1.1 → 8.2.1

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/README.md CHANGED
@@ -30,7 +30,16 @@ You can specify the package content in package.json.
30
30
  "pkg": {
31
31
  "content": {
32
32
  "/some/location" : { "base": "build" },
33
- "/etc/myconfig.json" : "sample-config.json"
33
+ "/etc/myconfig.json" : "sample-config.json",
34
+ "/opt/myapp": [
35
+ {
36
+ "type": "npm-pack"
37
+ },
38
+ {
39
+ "type": "node-modules",
40
+ "withoutDevelpmentDependencies": true
41
+ }
42
+ ]
34
43
  },
35
44
  "hooks" : "pkg/hooks",
36
45
  "output": {
@@ -43,6 +52,24 @@ You can specify the package content in package.json.
43
52
  }
44
53
  ```
45
54
 
55
+ # content providers
56
+
57
+ # files (default)
58
+
59
+ content from the file system
60
+
61
+ ## npm-pack
62
+
63
+ content as provided by npm pack
64
+
65
+ ## node-modules
66
+
67
+ content of all (production) dependencies
68
+
69
+ options:
70
+ - withoutDevelpmentDependencies when to stip away dev dependencies
71
+
72
+
46
73
  # API
47
74
 
48
75
  <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "8.1.1",
3
+ "version": "8.2.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -40,8 +40,8 @@
40
40
  "lint:docs": "documentation lint ./src/**/*.mjs"
41
41
  },
42
42
  "dependencies": {
43
- "@npmcli/arborist": "^5.0.3",
44
- "aggregate-async-iterator": "^1.1.9",
43
+ "@npmcli/arborist": "^5.0.4",
44
+ "aggregate-async-iterator": "^1.1.10",
45
45
  "commander": "^9.1.0",
46
46
  "content-entry": "^4.1.9",
47
47
  "content-entry-filesystem": "^4.0.9",
@@ -27,7 +27,7 @@ export class NodeModulesContentProvider extends ContentProvider {
27
27
 
28
28
  constructor(definitions, entryProperties) {
29
29
  super();
30
- Object.assign(this, definitions);
30
+ Object.assign(this, { withoutDevelpmentDependencies: true }, definitions);
31
31
  this.entryProperties = entryProperties;
32
32
  }
33
33
 
@@ -36,51 +36,65 @@ export class NodeModulesContentProvider extends ContentProvider {
36
36
  }
37
37
 
38
38
  async *[Symbol.asyncIterator]() {
39
- const tmp = await mkdtemp(join(tmpdir(), "node-modules"));
39
+ let pkgSourceDir = this.dir;
40
40
 
41
- const json = JSON.parse(
42
- await readFile(join(this.dir, "package.json"), utf8StreamOptions)
43
- );
44
- delete json.devDependencies;
45
- await writeFile(
46
- join(tmp, "package.json"),
47
- JSON.stringify(json),
48
- utf8StreamOptions
49
- );
41
+ if (this.withoutDevelpmentDependencies) {
42
+ pkgSourceDir = await mkdtemp(join(tmpdir(), "node-modules"));
50
43
 
51
- // TODO find .npmrc
52
- const npmrc = parse(await readFile(join(homedir(), ".npmrc"), utf8StreamOptions));
53
- const arb = new Arborist({ path: tmp, ...npmrc });
54
- await arb.buildIdealTree({
55
- update: true,
56
- prune: true,
57
- saveType: "prod"
58
- });
59
- await arb.prune({ saveType: "prod" });
60
- await arb.reify({ save: true });
44
+ const json = JSON.parse(
45
+ await readFile(join(this.dir, "package.json"), utf8StreamOptions)
46
+ );
47
+ delete json.devDependencies;
48
+ await writeFile(
49
+ join(pkgSourceDir, "package.json"),
50
+ JSON.stringify(json),
51
+ utf8StreamOptions
52
+ );
53
+
54
+ // TODO find .npmrc
55
+ const npmrc = parse(
56
+ await readFile(join(homedir(), ".npmrc"), utf8StreamOptions)
57
+ );
58
+ const arb = new Arborist({ path: pkgSourceDir, ...npmrc });
59
+ await arb.buildIdealTree({
60
+ update: true,
61
+ prune: true,
62
+ saveType: "prod"
63
+ });
64
+ await arb.prune({ saveType: "prod" });
65
+ await arb.reify({ save: true });
66
+ }
61
67
 
62
68
  for (const name of await globby("node_modules/**/*", {
63
- cwd: tmp
69
+ cwd: pkgSourceDir
64
70
  })) {
65
71
  if (!toBeSkipped.test(name)) {
66
72
  if (name.endsWith("package.json")) {
67
- const json = shrinkNPM(
68
- JSON.parse(await readFile(join(tmp, name), utf8StreamOptions)),
69
- {}
70
- );
71
-
72
- if (json) {
73
- yield Object.assign(
74
- new StringContentEntry(name, JSON.stringify(json)),
75
- this.entryProperties
73
+ try {
74
+ const json = shrinkNPM(
75
+ JSON.parse(
76
+ await readFile(join(pkgSourceDir, name), utf8StreamOptions)
77
+ ),
78
+ {}
76
79
  );
80
+
81
+ if (json) {
82
+ yield Object.assign(
83
+ new StringContentEntry(name, JSON.stringify(json)),
84
+ this.entryProperties
85
+ );
86
+ }
87
+
88
+ continue;
89
+ } catch (e) {
90
+ console.error(e, name);
77
91
  }
78
- } else {
79
- yield Object.assign(
80
- new FileSystemEntry(name, tmp),
81
- this.entryProperties
82
- );
83
92
  }
93
+
94
+ yield Object.assign(
95
+ new FileSystemEntry(name, pkgSourceDir),
96
+ this.entryProperties
97
+ );
84
98
  }
85
99
  }
86
100
  }