npm-pkgbuild 11.5.23 → 11.6.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-pkgbuild",
3
- "version": "11.5.23",
3
+ "version": "11.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -44,6 +44,7 @@
44
44
  "@vercel/nft": "^0.22.5",
45
45
  "aggregate-async-iterator": "^1.1.16",
46
46
  "commander": "^10.0.0",
47
+ "compare-versions": "^6.0.0-rc.1",
47
48
  "content-entry": "^6.0.0",
48
49
  "content-entry-filesystem": "^5.2.13",
49
50
  "content-entry-transform": "^1.4.28",
@@ -2,6 +2,7 @@ import { join, resolve } from "node:path";
2
2
  import { packageDirectory } from "pkg-dir";
3
3
  import { packageWalker } from "npm-package-walker";
4
4
  import { createContext } from "expression-expander";
5
+ import { satisfies } from "compare-versions";
5
6
  import { asArray } from "./util.mjs";
6
7
  import { NPMPackContentProvider } from "./content/npm-pack-content-provider.mjs";
7
8
  import { NodeModulesContentProvider } from "./content/node-modules-content-provider.mjs";
@@ -112,8 +113,13 @@ export async function* extractFromPackage(options = {}, env = {}) {
112
113
  const fragments = {};
113
114
  let root, parent;
114
115
 
116
+ const packages = new Map();
117
+
115
118
  await packageWalker(async (packageContent, dir, modulePath) => {
116
119
  let i = 0;
120
+
121
+ packages.set(packageContent.name, packageContent.version);
122
+
117
123
  for (const pkgbuild of asArray(packageContent.pkgbuild)) {
118
124
  if (modulePath.length > 0 && !pkgbuild.variant) {
119
125
  continue;
@@ -128,11 +134,6 @@ export async function* extractFromPackage(options = {}, env = {}) {
128
134
  if (requires) {
129
135
  let fullfilled = true;
130
136
 
131
- /* TODO check dependencies later ?
132
- if(required.dependencies) {
133
- }
134
- */
135
-
136
137
  if (requires.properties) {
137
138
  for (const [k, v] of Object.entries(requires.properties)) {
138
139
  if (root.properties[k] !== v && options[k] !== v) {
@@ -152,23 +153,24 @@ export async function* extractFromPackage(options = {}, env = {}) {
152
153
  }
153
154
 
154
155
  if (fullfilled) {
155
- if(options.verbose) {
156
+ if (options.verbose) {
156
157
  console.log(`${name}: requirement fullfilled`, requires);
157
158
  }
158
159
  } else {
159
- if(options.verbose) {
160
+ if (options.verbose) {
160
161
  console.log(`${name}: requirement not fullfilled`, requires);
161
162
  }
162
163
  continue;
163
164
  }
164
165
  } else {
165
- if(options.verbose) {
166
+ if (options.verbose) {
166
167
  console.log(`${name}: load`);
167
168
  }
168
169
  }
169
170
 
170
171
  const fragment = {
171
172
  name,
173
+ requires, // check remaining requirements later
172
174
  priority,
173
175
  depends: packageContent.engines || {},
174
176
  arch: new Set(),
@@ -285,12 +287,29 @@ export async function* extractFromPackage(options = {}, env = {}) {
285
287
  fragment;
286
288
  fragment = fragments[fragment.parent]
287
289
  ) {
288
- arch = new Set([...arch, ...fragment.arch]);
289
- properties = Object.assign({}, fragment.properties, properties);
290
- Object.assign(depends, fragment.depends);
291
- Object.assign(output, fragment.output);
292
- if (fragment.content) {
293
- content.push([fragment.content, fragment.dir]);
290
+ let requirementsMet = true;
291
+
292
+ if (fragment?.requires?.dependencies) {
293
+ for (const [p, v] of Object.entries(fragment.requires.dependencies)) {
294
+ const pkgVersion = packages.get(p);
295
+
296
+ if (pkgVersion === undefined || !satisfies(pkgVersion, v)) {
297
+ requirementsMet = false;
298
+ break;
299
+ }
300
+ }
301
+ }
302
+
303
+ if (requirementsMet) {
304
+ arch = new Set([...arch, ...fragment.arch]);
305
+ properties = Object.assign({}, fragment.properties, properties);
306
+ Object.assign(depends, fragment.depends);
307
+ Object.assign(output, fragment.output);
308
+ if (fragment.content) {
309
+ content.push([fragment.content, fragment.dir]);
310
+ }
311
+ } else {
312
+ console.log("requirements not met", fragment.name);
294
313
  }
295
314
  }
296
315
 
@@ -313,7 +332,7 @@ export async function* extractFromPackage(options = {}, env = {}) {
313
332
  properties: context.expand(properties)
314
333
  };
315
334
 
316
- /*
335
+ /*
317
336
  console.log(
318
337
  "RESULT",
319
338
  result.variant,
@@ -65,8 +65,11 @@ export class DOCKER extends Packager {
65
65
  }
66
66
 
67
67
  async function* trailingLines() {
68
- if (options.entrypoints) {
69
- yield `ENTRYPOINT ["node", ${Object.values(options.entrypoints)[0]}]\n`;
68
+ yield "WORKDIR /app\n";
69
+ yield "COPY . .\n";
70
+ if (properties.entrypoints) {
71
+ yield `ENTRYPOINT ["node", ${Object.values(properties.entrypoints)[0]}]\n`;
72
+ yield `CMD [ "node", ${Object.values(properties.entrypoints)[0]} ]\n`;
70
73
  }
71
74
  }
72
75
 
@@ -105,16 +108,20 @@ export class DOCKER extends Packager {
105
108
  let image = "";
106
109
 
107
110
  if (!options.dry) {
108
- const docker = await execa(this.constructor.name, ["build", "--tag", tag, staging], {
109
- cwd: staging
110
- });
111
+ const docker = await execa(
112
+ this.constructor.name,
113
+ ["build", "--tag", tag, staging],
114
+ {
115
+ cwd: staging
116
+ }
117
+ );
111
118
 
112
119
  const lines = docker.stderr.split(/\n/);
113
- const wl = lines.filter(l=>l.match(/writing\s+image/));
114
- if(wl?.[0]) {
115
- image = wl[0].split(/\s+/)[3];
120
+ const wl = lines.filter(l => l.match(/writing\s+image/));
121
+ if (wl?.[0]) {
122
+ image = wl[0].split(/\s+/)[3];
116
123
  }
117
-
124
+
118
125
  if (options.verbose) {
119
126
  console.log(docker.stderr);
120
127
  console.log(docker.stdout);