nf3 0.3.0 → 0.3.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/dist/_chunks/trace.mjs
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import { a as relative, o as resolve, r as join
|
|
1
|
+
import { a as relative, i as normalize, n as isAbsolute, o as resolve, r as join, t as dirname } from "./libs/pathe.mjs";
|
|
2
2
|
import { n as writePackageJSON, t as readPackageJSON } from "./libs/pkg-types.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { promises } from "node:fs";
|
|
5
5
|
import { nodeFileTrace } from "@vercel/nft";
|
|
6
|
-
import { isAbsolute } from "node:path";
|
|
7
6
|
import semver from "semver";
|
|
8
|
-
import { join } from "node:path/posix";
|
|
9
7
|
|
|
10
8
|
//#region src/_utils.ts
|
|
11
9
|
const isWindows = process.platform === "win32";
|
|
12
|
-
const NODE_MODULES_RE = /^(?<dir
|
|
13
|
-
function parseNodeModulePath(path
|
|
14
|
-
return NODE_MODULES_RE.exec(path
|
|
10
|
+
const NODE_MODULES_RE = /^(?<dir>.+[\\/]node_modules[\\/])(?<name>[^@\\/]+|@[^\\/]+[\\/][^\\/]+)(?:[\\/](?<subpath>.+))?$/;
|
|
11
|
+
function parseNodeModulePath(path) {
|
|
12
|
+
return NODE_MODULES_RE.exec(path)?.groups || {};
|
|
15
13
|
}
|
|
16
|
-
const IMPORT_RE = /^(?!\.)(?<name>[
|
|
14
|
+
const IMPORT_RE = /^(?!\.)(?<name>[^@/\\]+|@[^/\\]+[/\\][^/\\]+)(?:[/\\](?<subpath>.+))?$/;
|
|
17
15
|
function toImport(id) {
|
|
18
16
|
if (isAbsolute(id)) {
|
|
19
17
|
const { name, subpath } = parseNodeModulePath(id) || {};
|
|
20
18
|
if (name && subpath) return join(name, subpath);
|
|
21
19
|
} else if (IMPORT_RE.test(id)) return id;
|
|
22
20
|
}
|
|
23
|
-
function guessSubpath(path
|
|
24
|
-
const { dir, name, subpath } = NODE_MODULES_RE.exec(path
|
|
21
|
+
function guessSubpath(path, conditions) {
|
|
22
|
+
const { dir, name, subpath } = NODE_MODULES_RE.exec(path)?.groups || {};
|
|
25
23
|
if (!dir || !name || !subpath) return;
|
|
26
24
|
const exports = getPkgJSON(join(dir, name) + "/")?.exports;
|
|
27
25
|
if (!exports || typeof exports !== "object") return;
|
|
@@ -95,17 +93,17 @@ async function traceNodeModules(input, opts) {
|
|
|
95
93
|
...opts.nft
|
|
96
94
|
});
|
|
97
95
|
await opts?.hooks?.traceResult?.(traceResult);
|
|
98
|
-
const _resolveTracedPath = (p) => promises.realpath(resolve(opts.nft?.base || "/", p));
|
|
96
|
+
const _resolveTracedPath = (p) => promises.realpath(resolve(opts.nft?.base || "/", p)).then((p$1) => normalize(p$1));
|
|
99
97
|
const tracedFiles = Object.fromEntries(await Promise.all([...traceResult.reasons.entries()].map(async ([_path, reasons]) => {
|
|
100
98
|
if (reasons.ignored) return;
|
|
101
|
-
const path
|
|
102
|
-
if (!path
|
|
103
|
-
if (!await isFile(path
|
|
104
|
-
const { dir: baseDir, name: pkgName, subpath } = parseNodeModulePath(path
|
|
99
|
+
const path = await _resolveTracedPath(_path);
|
|
100
|
+
if (!path.includes("node_modules")) return;
|
|
101
|
+
if (!await isFile(path)) return;
|
|
102
|
+
const { dir: baseDir, name: pkgName, subpath } = parseNodeModulePath(path);
|
|
105
103
|
if (!baseDir || !pkgName) return;
|
|
106
|
-
const pkgPath = join
|
|
107
|
-
return [path
|
|
108
|
-
path
|
|
104
|
+
const pkgPath = join(baseDir, pkgName);
|
|
105
|
+
return [path, {
|
|
106
|
+
path,
|
|
109
107
|
parents: await Promise.all([...reasons.parents].map((p) => _resolveTracedPath(p))),
|
|
110
108
|
subpath,
|
|
111
109
|
pkgName,
|
|
@@ -163,7 +161,7 @@ async function traceNodeModules(input, opts) {
|
|
|
163
161
|
}
|
|
164
162
|
const pkgJSON = pkg.versions[version].pkgJSON;
|
|
165
163
|
applyProductionCondition(pkgJSON.exports);
|
|
166
|
-
const pkgJSONPath = join
|
|
164
|
+
const pkgJSONPath = join(outDir, pkgPath, "package.json");
|
|
167
165
|
await promises.mkdir(dirname(pkgJSONPath), { recursive: true });
|
|
168
166
|
await promises.writeFile(pkgJSONPath, JSON.stringify(pkgJSON, null, 2), "utf8");
|
|
169
167
|
if (opts.traceAlias && opts.traceAlias[pkgPath]) {
|
|
@@ -172,8 +170,8 @@ async function traceNodeModules(input, opts) {
|
|
|
172
170
|
}
|
|
173
171
|
};
|
|
174
172
|
const linkPackage = async (from, to) => {
|
|
175
|
-
const src = join
|
|
176
|
-
const dst = join
|
|
173
|
+
const src = join(outDir, from);
|
|
174
|
+
const dst = join(outDir, to);
|
|
177
175
|
if ((await promises.lstat(dst).catch(() => null))?.isSymbolicLink()) return;
|
|
178
176
|
await promises.mkdir(dirname(dst), { recursive: true });
|
|
179
177
|
await promises.symlink(relative(dirname(dst), src), dst, isWindows ? "junction" : "dir").catch((error) => {
|
|
@@ -181,7 +179,7 @@ async function traceNodeModules(input, opts) {
|
|
|
181
179
|
});
|
|
182
180
|
};
|
|
183
181
|
const findPackageParents = (pkg, version) => {
|
|
184
|
-
const versionFiles = pkg.versions[version].files.map((path
|
|
182
|
+
const versionFiles = pkg.versions[version].files.map((path) => tracedFiles[path]);
|
|
185
183
|
return [...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
|
|
186
184
|
const parentFile = tracedFiles[parentPath];
|
|
187
185
|
if (!parentFile || parentFile.pkgName === pkg.name) return null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";if(process.platform!==`darwin`)throw Error(`Module 'fsevents' is not compatible with platform '${process.platform}'`);const Native=require(`./fsevents.node`),events=Native.constants;function watch(i,a,o){if(typeof i!=`string`)throw TypeError(`fsevents argument 1 must be a string and not a ${typeof i}`);if(typeof a==`function`&&o===void 0&&(o=a,a=Native.flags.SinceNow),typeof a!=`number`)throw TypeError(`fsevents argument 2 must be a number and not a ${typeof a}`);if(typeof o!=`function`)throw TypeError(`fsevents argument 3 must be a function and not a ${typeof o}`);let s=Native.start(Native.global,i,a,o);if(!s)throw Error(`could not watch: ${i}`);return()=>{let i=s?Promise.resolve(s).then(Native.stop):Promise.resolve(void 0);return s=void 0,i}}function getInfo(e,i){return{path:e,flags:i,event:getEventType(i),type:getFileType(i),changes:getFileChanges(i)}}function getFileType(e){if(events.ItemIsFile&e)return`file`;if(events.ItemIsDir&e||events.MustScanSubDirs&e)return`directory`;if(events.ItemIsSymlink&e)return`symlink`}function anyIsTrue(e){for(let i in e)if(e[i])return!0;return!1}function getEventType(e){return events.ItemRemoved&e?`deleted`:events.ItemRenamed&e?`moved`:events.ItemCreated&e?`created`:events.ItemModified&e?`modified`:events.RootChanged&e?`root-changed`:events.ItemCloned&e?`cloned`:anyIsTrue(e)?`modified`:`unknown`}function getFileChanges(e){return{inode:!!(events.ItemInodeMetaMod&e),finder:!!(events.ItemFinderInfoMod&e),access:!!(events.ItemChangeOwner&e),xattrs:!!(events.ItemXattrMod&e)}}exports.watch=watch,exports.getInfo=getInfo,exports.constants=events;
|
|
Binary file
|