npm-pkgbuild 10.4.0 → 10.5.0
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/package.json
CHANGED
|
@@ -37,94 +37,90 @@ export class NodeModulesContentProvider extends ContentProvider {
|
|
|
37
37
|
|
|
38
38
|
async *[Symbol.asyncIterator]() {
|
|
39
39
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (this.withoutDevelpmentDependencies) {
|
|
43
|
-
pkgSourceDir = await mkdtemp(join(tmpdir(), "node-modules"));
|
|
44
|
-
|
|
45
|
-
const json = JSON.parse(
|
|
46
|
-
await readFile(join(this.dir, "package.json"), utf8StreamOptions)
|
|
47
|
-
);
|
|
48
|
-
delete json.devDependencies;
|
|
49
|
-
await writeFile(
|
|
50
|
-
join(pkgSourceDir, "package.json"),
|
|
51
|
-
JSON.stringify(json),
|
|
52
|
-
utf8StreamOptions
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
let npmrcContent;
|
|
56
|
-
|
|
57
|
-
const searchDirs = [pkgSourceDir, homedir()];
|
|
58
|
-
for(const d of searchDirs) {
|
|
59
|
-
try {
|
|
60
|
-
npmrcContent = await readFile(join(d, ".npmrc"), utf8StreamOptions);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
catch {}
|
|
64
|
-
}
|
|
40
|
+
let pkgSourceDir = this.dir;
|
|
65
41
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
42
|
+
if (this.withoutDevelpmentDependencies) {
|
|
43
|
+
pkgSourceDir = await mkdtemp(join(tmpdir(), "node-modules"));
|
|
44
|
+
|
|
45
|
+
const json = JSON.parse(
|
|
46
|
+
await readFile(join(this.dir, "package.json"), utf8StreamOptions)
|
|
47
|
+
);
|
|
48
|
+
delete json.devDependencies;
|
|
49
|
+
await writeFile(
|
|
50
|
+
join(pkgSourceDir, "package.json"),
|
|
51
|
+
JSON.stringify(json),
|
|
52
|
+
utf8StreamOptions
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
let npmrcContent;
|
|
56
|
+
|
|
57
|
+
const searchDirs = [pkgSourceDir, homedir()];
|
|
58
|
+
for (const d of searchDirs) {
|
|
59
|
+
try {
|
|
60
|
+
npmrcContent = await readFile(join(d, ".npmrc"), utf8StreamOptions);
|
|
61
|
+
break;
|
|
62
|
+
} catch {}
|
|
74
63
|
}
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
|
|
65
|
+
let npmrc = {};
|
|
66
|
+
|
|
67
|
+
if (npmrcContent) {
|
|
68
|
+
npmrc = parse(npmrcContent);
|
|
69
|
+
} else {
|
|
70
|
+
if (process.env.NPM_TOKEN) {
|
|
71
|
+
npmrc["_authToken"] = process.env.NPM_TOKEN;
|
|
72
|
+
} else {
|
|
73
|
+
throw new Error(`.npmrc not found in ${searchDirs}`);
|
|
74
|
+
}
|
|
77
75
|
}
|
|
76
|
+
|
|
77
|
+
const arb = new Arborist({ path: pkgSourceDir, ...npmrc });
|
|
78
|
+
await arb.buildIdealTree({
|
|
79
|
+
update: true,
|
|
80
|
+
prune: true,
|
|
81
|
+
saveType: "prod"
|
|
82
|
+
});
|
|
83
|
+
await arb.prune({ saveType: "prod" });
|
|
84
|
+
await arb.reify({ save: true });
|
|
78
85
|
}
|
|
79
|
-
|
|
80
|
-
const arb = new Arborist({ path: pkgSourceDir, ...npmrc });
|
|
81
|
-
await arb.buildIdealTree({
|
|
82
|
-
update: true,
|
|
83
|
-
prune: true,
|
|
84
|
-
saveType: "prod"
|
|
85
|
-
});
|
|
86
|
-
await arb.prune({ saveType: "prod" });
|
|
87
|
-
await arb.reify({ save: true });
|
|
88
|
-
}
|
|
89
86
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
if (json) {
|
|
104
|
-
yield Object.assign(
|
|
105
|
-
new StringContentEntry(name, JSON.stringify(json)),
|
|
106
|
-
this.entryProperties
|
|
87
|
+
for (const name of await globby("node_modules/**/*", {
|
|
88
|
+
cwd: pkgSourceDir
|
|
89
|
+
})) {
|
|
90
|
+
if (!toBeSkipped.test(name)) {
|
|
91
|
+
if (name.endsWith("package.json")) {
|
|
92
|
+
try {
|
|
93
|
+
const json = shrinkNPM(
|
|
94
|
+
JSON.parse(
|
|
95
|
+
await readFile(join(pkgSourceDir, name), utf8StreamOptions)
|
|
96
|
+
),
|
|
97
|
+
{}
|
|
107
98
|
);
|
|
108
|
-
}
|
|
109
99
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
if (json) {
|
|
101
|
+
yield Object.assign(
|
|
102
|
+
new StringContentEntry(name, JSON.stringify(json)),
|
|
103
|
+
this.entryProperties
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
continue;
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.error(e, name);
|
|
110
|
+
}
|
|
113
111
|
}
|
|
112
|
+
|
|
113
|
+
yield Object.assign(
|
|
114
|
+
new FileSystemEntry(name, pkgSourceDir),
|
|
115
|
+
this.entryProperties
|
|
116
|
+
);
|
|
114
117
|
}
|
|
115
|
-
|
|
116
|
-
yield Object.assign(
|
|
117
|
-
new FileSystemEntry(name, pkgSourceDir),
|
|
118
|
-
this.entryProperties
|
|
119
|
-
);
|
|
120
118
|
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error(e);
|
|
121
|
+
throw e;
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
|
-
catch(e) {
|
|
124
|
-
console.error(e);
|
|
125
|
-
throw e;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
124
|
}
|
|
129
125
|
|
|
130
126
|
const toBeSkipped = new RegExp(
|
|
@@ -31,7 +31,7 @@ export const npmArchMapping = {
|
|
|
31
31
|
const entryAttributeNames = ["owner", "group", "mode"];
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* @typedef {Object} PackageDefinition
|
|
34
|
+
* @typedef {Object} PackageDefinition
|
|
35
35
|
* @property {Object} properties values describing the package attributes
|
|
36
36
|
* @property {ContentProvider[]} sources content providers
|
|
37
37
|
* @property {Object} dependencies
|
|
@@ -44,12 +44,13 @@ const entryAttributeNames = ["owner", "group", "mode"];
|
|
|
44
44
|
* - for each architecture deliver a new result
|
|
45
45
|
* - if not architecture is given one result set is provided nethertheless
|
|
46
46
|
* - architectures are taken from cpu (node arch ids) and from pkgbuild.arch (raw arch ids)
|
|
47
|
-
* - architecture given in a abstract definition are used to reduce the set of avaliable architectures
|
|
47
|
+
* - architecture given in a abstract definition are used to reduce the set of avaliable architectures
|
|
48
48
|
* @param {Object} pkg package.json content
|
|
49
49
|
* @param {string} dir
|
|
50
|
+
* @param {Object} options
|
|
50
51
|
* @returns {AsyncIter<PackageDefinition>}
|
|
51
52
|
*/
|
|
52
|
-
export async function* extractFromPackage(json, dir) {
|
|
53
|
+
export async function* extractFromPackage(json, dir, options = {}) {
|
|
53
54
|
const properties = Object.fromEntries(
|
|
54
55
|
["name", "version", "description", "homepage", "license"]
|
|
55
56
|
.map(key => [key, json[key]])
|
|
@@ -98,24 +99,24 @@ export async function* extractFromPackage(json, dir) {
|
|
|
98
99
|
let output = {};
|
|
99
100
|
let arch = new Set();
|
|
100
101
|
let restrictArch = new Set();
|
|
101
|
-
|
|
102
|
+
|
|
102
103
|
const processPkg = (json, dir, modulePath) => {
|
|
103
104
|
const pkg = json.pkgbuild;
|
|
104
105
|
|
|
105
106
|
if (pkg) {
|
|
106
|
-
if(!modulePath) {
|
|
107
|
+
if (!modulePath) {
|
|
107
108
|
if (json.cpu) {
|
|
108
109
|
for (const a of asArray(json.cpu)) {
|
|
109
110
|
arch.add(npmArchMapping[a]);
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
|
-
if(pkg.arch) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
if (pkg.arch) {
|
|
114
|
+
for (const a of asArray(pkg.arch)) {
|
|
115
|
+
arch.add(a);
|
|
116
|
+
}
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
+
|
|
119
120
|
if (pkg.abstract || !modulePath) {
|
|
120
121
|
if (pkg.variant) {
|
|
121
122
|
variant = pkg.variant;
|
|
@@ -186,12 +187,23 @@ export async function* extractFromPackage(json, dir) {
|
|
|
186
187
|
|
|
187
188
|
if (arch.size > 0) {
|
|
188
189
|
// provide each arch separadly
|
|
190
|
+
|
|
191
|
+
let numberOfArchs = 0;
|
|
192
|
+
|
|
189
193
|
for (const a of arch) {
|
|
190
|
-
if(!restrictArch.size || restrictArch.has(a)) {
|
|
191
|
-
|
|
192
|
-
|
|
194
|
+
if (!restrictArch.size || restrictArch.has(a)) {
|
|
195
|
+
if (options.available && npmArchMapping[process.arch] !== a) {
|
|
196
|
+
break;
|
|
197
|
+
} else {
|
|
198
|
+
numberOfArchs++;
|
|
199
|
+
properties.arch = [a];
|
|
200
|
+
yield { properties, sources, dependencies, output, variant };
|
|
201
|
+
}
|
|
193
202
|
}
|
|
194
203
|
}
|
|
204
|
+
if (numberOfArchs === 0) {
|
|
205
|
+
console.warn(`No matching arch remaining was ${[...arch]}`);
|
|
206
|
+
}
|
|
195
207
|
} else {
|
|
196
208
|
// or one set if no arch is given
|
|
197
209
|
yield { properties, sources, dependencies, output, variant };
|
package/src/npm-pkgbuild-cli.mjs
CHANGED
|
@@ -38,7 +38,7 @@ program
|
|
|
38
38
|
Object.assign(former, Object.fromEntries([str.split(/=/)]))
|
|
39
39
|
)
|
|
40
40
|
.option("-p --pkgdir <dir>", "which package to use", process.cwd())
|
|
41
|
-
.option("-a --available", "only
|
|
41
|
+
.option("-a --available", "only execute availabe output methods", false)
|
|
42
42
|
.option("--continue", "continue on error")
|
|
43
43
|
.option(
|
|
44
44
|
"-c --content <dir>",
|
|
@@ -85,7 +85,8 @@ program
|
|
|
85
85
|
JSON.parse(
|
|
86
86
|
await readFile(join(pkgDir, "package.json"), utf8StreamOptions)
|
|
87
87
|
),
|
|
88
|
-
pkgDir
|
|
88
|
+
pkgDir,
|
|
89
|
+
options
|
|
89
90
|
)) {
|
|
90
91
|
for (const inputFactory of allInputs.filter(
|
|
91
92
|
inputFactory => options[inputFactory.name] === true
|