npmdata 0.18.11 → 0.18.13
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/cli/actions/check.js +3 -3
- package/dist/cli/actions/extract.d.ts.map +1 -1
- package/dist/cli/actions/extract.js +4 -3
- package/dist/cli/actions/extract.js.map +1 -1
- package/dist/cli/actions/purge.d.ts.map +1 -1
- package/dist/cli/actions/purge.js +2 -3
- package/dist/cli/actions/purge.js.map +1 -1
- package/dist/cli/progress.d.ts +6 -0
- package/dist/cli/progress.d.ts.map +1 -0
- package/dist/cli/progress.js +12 -0
- package/dist/cli/progress.js.map +1 -0
- package/dist/fileset/execute.d.ts.map +1 -1
- package/dist/fileset/execute.js +8 -7
- package/dist/fileset/execute.js.map +1 -1
- package/dist/fileset/gitignore.d.ts +4 -0
- package/dist/fileset/gitignore.d.ts.map +1 -1
- package/dist/fileset/gitignore.js +12 -0
- package/dist/fileset/gitignore.js.map +1 -1
- package/dist/fileset/package-files.d.ts.map +1 -1
- package/dist/fileset/package-files.js +8 -0
- package/dist/fileset/package-files.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/npmdata-0.0.1.tgz +0 -0
- package/dist/package/action-check.d.ts +11 -3
- package/dist/package/action-check.d.ts.map +1 -1
- package/dist/package/action-check.js +42 -109
- package/dist/package/action-check.js.map +1 -1
- package/dist/package/action-extract.d.ts +6 -3
- package/dist/package/action-extract.d.ts.map +1 -1
- package/dist/package/action-extract.js +206 -229
- package/dist/package/action-extract.js.map +1 -1
- package/dist/package/action-init.d.ts.map +1 -1
- package/dist/package/action-init.js +1 -3
- package/dist/package/action-init.js.map +1 -1
- package/dist/package/action-purge.d.ts +6 -11
- package/dist/package/action-purge.d.ts.map +1 -1
- package/dist/package/action-purge.js +101 -137
- package/dist/package/action-purge.js.map +1 -1
- package/dist/package/calculate-diff.d.ts +12 -0
- package/dist/package/calculate-diff.d.ts.map +1 -0
- package/dist/package/calculate-diff.js +119 -0
- package/dist/package/calculate-diff.js.map +1 -0
- package/dist/package/config-merge.d.ts +2 -1
- package/dist/package/config-merge.d.ts.map +1 -1
- package/dist/package/config-merge.js +20 -4
- package/dist/package/config-merge.js.map +1 -1
- package/dist/package/resolve-files.d.ts +21 -0
- package/dist/package/resolve-files.d.ts.map +1 -0
- package/dist/package/resolve-files.js +198 -0
- package/dist/package/resolve-files.js.map +1 -0
- package/dist/types.d.ts +86 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +37 -10
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProgressEvent, BasicPackageOptions } from '../types';
|
|
2
2
|
export type PurgeOptions = BasicPackageOptions & {
|
|
3
3
|
onProgress?: (event: ProgressEvent) => void;
|
|
4
|
-
visitedEntries?: Set<string>;
|
|
5
|
-
config?: NpmdataConfig;
|
|
6
|
-
presets?: string[];
|
|
7
4
|
};
|
|
8
5
|
export type PurgeSummary = {
|
|
9
6
|
deleted: number;
|
|
@@ -11,14 +8,12 @@ export type PurgeSummary = {
|
|
|
11
8
|
dirsRemoved: number;
|
|
12
9
|
};
|
|
13
10
|
/**
|
|
14
|
-
* Purge managed files
|
|
15
|
-
* Supports --dry-run.
|
|
11
|
+
* Purge all managed files for the given entries.
|
|
16
12
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* the marker (removing only purged paths) and gitignore accordingly.
|
|
13
|
+
* Uses resolveFiles() to build the desired file list (installing packages as needed),
|
|
14
|
+
* then calculateDiff() to find the managed files on disk. Deletes ok, conflict,
|
|
15
|
+
* and extra files (i.e. everything currently managed by npmdata for these packages).
|
|
16
|
+
* Updates .npmdata markers and .gitignore entries for affected output directories.
|
|
22
17
|
*/
|
|
23
18
|
export declare function actionPurge(options: PurgeOptions): Promise<PurgeSummary>;
|
|
24
19
|
//# sourceMappingURL=action-purge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-purge.d.ts","sourceRoot":"","sources":["../../src/package/action-purge.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"action-purge.d.ts","sourceRoot":"","sources":["../../src/package/action-purge.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAa,MAAM,UAAU,CAAC;AASzE,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG;IAC/C,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAkD9E"}
|
|
@@ -1,166 +1,130 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
6
|
exports.actionPurge = actionPurge;
|
|
40
7
|
/* eslint-disable no-console */
|
|
41
|
-
const node_fs_1 =
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
42
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
43
10
|
const utils_1 = require("../utils");
|
|
44
11
|
const markers_1 = require("../fileset/markers");
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const
|
|
12
|
+
const gitignore_1 = require("../fileset/gitignore");
|
|
13
|
+
const symlinks_1 = require("./symlinks");
|
|
14
|
+
const resolve_files_1 = require("./resolve-files");
|
|
15
|
+
const calculate_diff_1 = require("./calculate-diff");
|
|
48
16
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
17
|
+
* Purge all managed files for the given entries.
|
|
18
|
+
*
|
|
19
|
+
* Uses resolveFiles() to build the desired file list (installing packages as needed),
|
|
20
|
+
* then calculateDiff() to find the managed files on disk. Deletes ok, conflict,
|
|
21
|
+
* and extra files (i.e. everything currently managed by npmdata for these packages).
|
|
22
|
+
* Updates .npmdata markers and .gitignore entries for affected output directories.
|
|
51
23
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const entriesToProcess = entries.filter((entry) => !visitedEntries.has(entryKey(entry)));
|
|
56
|
-
for (const entry of entriesToProcess) {
|
|
57
|
-
visitedEntries.add(entryKey(entry));
|
|
58
|
-
}
|
|
24
|
+
async function actionPurge(options) {
|
|
25
|
+
const { entries, cwd, dryRun = false, verbose = false, onProgress } = options;
|
|
26
|
+
const summary = { deleted: 0, symlinksRemoved: 0, dirsRemoved: 0 };
|
|
59
27
|
if (verbose) {
|
|
60
|
-
console.log(`[verbose]
|
|
28
|
+
console.log(`[verbose] actionPurge: resolving files (cwd: ${(0, utils_1.formatDisplayPath)(cwd, cwd)})`);
|
|
61
29
|
}
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
30
|
+
try {
|
|
31
|
+
const resolvedFiles = await (0, resolve_files_1.resolveFiles)(entries, {
|
|
32
|
+
cwd,
|
|
33
|
+
verbose,
|
|
34
|
+
onProgress: (e) => {
|
|
35
|
+
if (e.type === 'package-start' || e.type === 'package-end')
|
|
36
|
+
onProgress?.(e);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
65
39
|
if (verbose) {
|
|
66
|
-
console.log(`[verbose]
|
|
40
|
+
console.log(`[verbose] actionPurge: resolved ${resolvedFiles.length} desired file(s)`);
|
|
67
41
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
42
|
+
const managedResolvedFiles = resolvedFiles.filter((f) => f.managed);
|
|
43
|
+
const diff = await (0, calculate_diff_1.calculateDiff)(managedResolvedFiles, verbose, cwd);
|
|
44
|
+
// Purge: ok (present+matching), conflict (present+mismatched), extra (stale managed)
|
|
45
|
+
const filesToDelete = [...diff.ok, ...diff.conflict, ...diff.extra];
|
|
46
|
+
if (verbose) {
|
|
47
|
+
console.log(`[verbose] actionPurge: ${filesToDelete.length} file(s) to delete` +
|
|
48
|
+
` (ok=${diff.ok.length} conflict=${diff.conflict.length} extra=${diff.extra.length})`);
|
|
49
|
+
}
|
|
50
|
+
// Group by outputDir
|
|
51
|
+
const byOutputDir = new Map();
|
|
52
|
+
for (const entry of filesToDelete) {
|
|
53
|
+
const arr = byOutputDir.get(entry.outputDir) ?? [];
|
|
54
|
+
arr.push(entry);
|
|
55
|
+
byOutputDir.set(entry.outputDir, arr);
|
|
56
|
+
}
|
|
57
|
+
for (const [outputDir, dirEntries] of byOutputDir) {
|
|
58
|
+
await purgeOutputDir(outputDir, dirEntries, dryRun, summary, cwd, onProgress, verbose);
|
|
59
|
+
}
|
|
60
|
+
return summary;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
(0, utils_1.cleanupTempPackageJson)(cwd, verbose);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function purgeOutputDir(outputDir, entries, dryRun, summary, cwd, onProgress, verbose) {
|
|
67
|
+
const relPaths = entries.map((e) => e.relPath);
|
|
68
|
+
const gitignorePaths = (0, gitignore_1.readManagedGitignoreEntries)(outputDir);
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
const fullPath = node_path_1.default.join(outputDir, entry.relPath);
|
|
71
|
+
if (node_fs_1.default.existsSync(fullPath)) {
|
|
72
|
+
if (!dryRun) {
|
|
73
|
+
try {
|
|
74
|
+
node_fs_1.default.chmodSync(fullPath, 0o644);
|
|
75
|
+
node_fs_1.default.unlinkSync(fullPath);
|
|
100
76
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const filteredSets = presetFilteredSets.filter((e) => (0, utils_1.parsePackageSpec)(e.package).name !== pkg.name ||
|
|
104
|
-
(entry.selector?.presets?.length ?? 0) > 0);
|
|
105
|
-
if (filteredSets.length > 0) {
|
|
106
|
-
const outputConfig = entry.output ?? {};
|
|
107
|
-
const inheritedEntries = filteredSets.map((depEntry) => {
|
|
108
|
-
const { path: depPath, ...restOutput } = depEntry.output ?? {};
|
|
109
|
-
return {
|
|
110
|
-
...depEntry,
|
|
111
|
-
output: {
|
|
112
|
-
...restOutput,
|
|
113
|
-
path: node_path_1.default.join(outputConfig.path ?? '.', depPath ?? '.'),
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
if (verbose) {
|
|
118
|
-
console.log(`[verbose] purge: recursing into ${filteredSets.length} set(s) from ${pkg.name}`);
|
|
77
|
+
catch {
|
|
78
|
+
// ignore deletion errors
|
|
119
79
|
}
|
|
120
|
-
await collectPurgePlan(inheritedEntries, cwd, verbose, visitedEntries, plan, onProgress);
|
|
121
80
|
}
|
|
81
|
+
summary.deleted++;
|
|
82
|
+
const pkgName = entry.desired?.packageName ?? entry.existing?.packageName ?? '';
|
|
83
|
+
onProgress?.({
|
|
84
|
+
type: 'file-deleted',
|
|
85
|
+
packageName: pkgName,
|
|
86
|
+
file: entry.relPath,
|
|
87
|
+
managed: true,
|
|
88
|
+
gitignore: gitignorePaths.has(entry.relPath),
|
|
89
|
+
});
|
|
122
90
|
}
|
|
123
91
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
* Operates in two phases:
|
|
130
|
-
* 1. Collect: recursively traverse all sets and accumulate the managed file
|
|
131
|
-
* entries to delete per output directory (no disk writes).
|
|
132
|
-
* 2. Execute: delete the collected files per output directory, then update
|
|
133
|
-
* the marker (removing only purged paths) and gitignore accordingly.
|
|
134
|
-
*/
|
|
135
|
-
async function actionPurge(options) {
|
|
136
|
-
const { entries, cwd, dryRun = false, verbose = false, onProgress, visitedEntries = new Set(), } = options;
|
|
137
|
-
// Phase 1: collect all entries to purge across all recursive sets
|
|
138
|
-
if (verbose) {
|
|
139
|
-
console.log(`[verbose] purge: phase 1 - collecting entries to purge (cwd: ${cwd})`);
|
|
92
|
+
if (!dryRun && relPaths.length > 0) {
|
|
93
|
+
summary.symlinksRemoved += await (0, symlinks_1.removeAllSymlinks)(outputDir);
|
|
94
|
+
summary.dirsRemoved += removeEmptyDirs(outputDir);
|
|
95
|
+
await updateMarkerAfterPurge(outputDir, new Set(relPaths));
|
|
96
|
+
await (0, gitignore_1.removeFromGitignore)(outputDir, relPaths);
|
|
140
97
|
}
|
|
141
|
-
const plan = new Map();
|
|
142
|
-
await collectPurgePlan(entries, cwd, verbose, visitedEntries, plan, onProgress);
|
|
143
|
-
const summary = { deleted: 0, symlinksRemoved: 0, dirsRemoved: 0 };
|
|
144
|
-
// Phase 2: execute deletions per output directory
|
|
145
98
|
if (verbose) {
|
|
146
|
-
|
|
147
|
-
console.log(`[verbose] purge: phase 2 - deleting ${total} entr${total === 1 ? 'y' : 'ies'} across ${plan.size} output dir(s)`);
|
|
99
|
+
console.log(`[verbose] actionPurge: ${(0, utils_1.formatDisplayPath)(outputDir, cwd)} — deleted ${relPaths.length} file(s)`);
|
|
148
100
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
101
|
+
}
|
|
102
|
+
async function updateMarkerAfterPurge(outputDir, purgedPaths) {
|
|
103
|
+
const current = await (0, markers_1.readOutputDirMarker)(outputDir);
|
|
104
|
+
const updated = current.filter((m) => !purgedPaths.has(m.path));
|
|
105
|
+
await (0, markers_1.writeMarker)((0, markers_1.markerPath)(outputDir), updated);
|
|
106
|
+
}
|
|
107
|
+
function removeEmptyDirs(dir) {
|
|
108
|
+
let count = 0;
|
|
109
|
+
if (!node_fs_1.default.existsSync(dir))
|
|
110
|
+
return count;
|
|
111
|
+
const recurse = (d) => {
|
|
112
|
+
for (const e of node_fs_1.default.readdirSync(d)) {
|
|
113
|
+
const full = node_path_1.default.join(d, e);
|
|
114
|
+
if (node_fs_1.default.statSync(full).isDirectory())
|
|
115
|
+
recurse(full);
|
|
152
116
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
117
|
+
try {
|
|
118
|
+
if (d !== dir && node_fs_1.default.readdirSync(d).length === 0) {
|
|
119
|
+
node_fs_1.default.rmdirSync(d);
|
|
120
|
+
count++;
|
|
121
|
+
}
|
|
156
122
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
summary.dirsRemoved += result.dirsRemoved;
|
|
160
|
-
if (verbose) {
|
|
161
|
-
console.log(`[verbose] purge: deleted ${result.deleted} files, ${result.symlinksRemoved} symlinks, ${result.dirsRemoved} dirs`);
|
|
123
|
+
catch {
|
|
124
|
+
// ignore
|
|
162
125
|
}
|
|
163
|
-
}
|
|
164
|
-
|
|
126
|
+
};
|
|
127
|
+
recurse(dir);
|
|
128
|
+
return count;
|
|
165
129
|
}
|
|
166
130
|
//# sourceMappingURL=action-purge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-purge.js","sourceRoot":"","sources":["../../src/package/action-purge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"action-purge.js","sourceRoot":"","sources":["../../src/package/action-purge.ts"],"names":[],"mappings":";;;;;AA+BA,kCAkDC;AAjFD,+BAA+B;AAC/B,sDAAyB;AACzB,0DAA6B;AAG7B,oCAAqE;AACrE,gDAAkF;AAClF,oDAAwF;AAExF,yCAA+C;AAC/C,mDAA+C;AAC/C,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KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ResolvedFile, DiffResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate the diff between the desired file list (from resolveFiles) and the
|
|
4
|
+
* actual state of each output directory.
|
|
5
|
+
*
|
|
6
|
+
* Only managed files (tracked in .npmdata markers) are included in the 'extra'
|
|
7
|
+
* analysis, scoped to the packages represented in `resolvedFiles`.
|
|
8
|
+
*
|
|
9
|
+
* @returns DiffResult classifying each file as ok, missing, extra, or conflict.
|
|
10
|
+
*/
|
|
11
|
+
export declare function calculateDiff(resolvedFiles: ResolvedFile[], verbose?: boolean, cwd?: string): Promise<DiffResult>;
|
|
12
|
+
//# sourceMappingURL=calculate-diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate-diff.d.ts","sourceRoot":"","sources":["../../src/package/calculate-diff.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAuB,MAAM,UAAU,CAAC;AAOzE;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,aAAa,EAAE,YAAY,EAAE,EAC7B,OAAO,CAAC,EAAE,OAAO,EACjB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,CAAC,CAgDrB"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.calculateDiff = calculateDiff;
|
|
7
|
+
/* eslint-disable no-console */
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const gitignore_1 = require("../fileset/gitignore");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
const markers_1 = require("../fileset/markers");
|
|
13
|
+
const content_replacements_1 = require("./content-replacements");
|
|
14
|
+
/**
|
|
15
|
+
* Calculate the diff between the desired file list (from resolveFiles) and the
|
|
16
|
+
* actual state of each output directory.
|
|
17
|
+
*
|
|
18
|
+
* Only managed files (tracked in .npmdata markers) are included in the 'extra'
|
|
19
|
+
* analysis, scoped to the packages represented in `resolvedFiles`.
|
|
20
|
+
*
|
|
21
|
+
* @returns DiffResult classifying each file as ok, missing, extra, or conflict.
|
|
22
|
+
*/
|
|
23
|
+
async function calculateDiff(resolvedFiles, verbose, cwd) {
|
|
24
|
+
const result = { ok: [], missing: [], extra: [], conflict: [] };
|
|
25
|
+
if (resolvedFiles.length === 0)
|
|
26
|
+
return result;
|
|
27
|
+
// Group resolved files by output directory
|
|
28
|
+
const byOutputDir = new Map();
|
|
29
|
+
for (const f of resolvedFiles) {
|
|
30
|
+
const arr = byOutputDir.get(f.outputDir) ?? [];
|
|
31
|
+
arr.push(f);
|
|
32
|
+
byOutputDir.set(f.outputDir, arr);
|
|
33
|
+
}
|
|
34
|
+
// Only consider marker entries from packages that appear in the resolved list
|
|
35
|
+
const relevantPackages = new Set(resolvedFiles.map((f) => f.packageName));
|
|
36
|
+
for (const [outputDir, desiredFiles] of byOutputDir) {
|
|
37
|
+
const existingMarker = await (0, markers_1.readOutputDirMarker)(outputDir);
|
|
38
|
+
const managedByPath = new Map(existingMarker.map((m) => [m.path, m]));
|
|
39
|
+
const desiredByPath = new Map(desiredFiles.map((f) => [f.relPath, f]));
|
|
40
|
+
const gitignorePaths = (0, gitignore_1.readManagedGitignoreEntries)(outputDir);
|
|
41
|
+
// ── Classify desired files ──────────────────────────────────────────────
|
|
42
|
+
for (const desired of desiredFiles) {
|
|
43
|
+
await classifyDesiredFile(desired, outputDir, managedByPath, gitignorePaths, result);
|
|
44
|
+
}
|
|
45
|
+
// ── Extra managed files ─────────────────────────────────────────────────
|
|
46
|
+
// Files that are managed (in the marker) under a relevant package but are
|
|
47
|
+
// no longer in the desired file list.
|
|
48
|
+
for (const m of existingMarker) {
|
|
49
|
+
if (relevantPackages.has(m.packageName) && !desiredByPath.has(m.path)) {
|
|
50
|
+
result.extra.push({ status: 'extra', relPath: m.path, outputDir, existing: m });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (verbose) {
|
|
54
|
+
console.log(`[verbose] calculateDiff: ${(0, utils_1.formatDisplayPath)(outputDir, cwd)}: ` +
|
|
55
|
+
`ok=${result.ok.length} missing=${result.missing.length} ` +
|
|
56
|
+
`conflict=${result.conflict.length} extra=${result.extra.length}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Classify a single desired file against the current output directory state.
|
|
63
|
+
* Appends to the appropriate result bucket (ok, missing, or conflict).
|
|
64
|
+
*/
|
|
65
|
+
async function classifyDesiredFile(desired, outputDir, managedByPath, gitignorePaths, result) {
|
|
66
|
+
const destPath = node_path_1.default.join(outputDir, desired.relPath);
|
|
67
|
+
const destExists = node_fs_1.default.existsSync(destPath);
|
|
68
|
+
if (!destExists) {
|
|
69
|
+
result.missing.push({ status: 'missing', relPath: desired.relPath, outputDir, desired });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const conflictReasons = [];
|
|
73
|
+
// Content check
|
|
74
|
+
let srcHash;
|
|
75
|
+
try {
|
|
76
|
+
if (desired.contentReplacements.length > 0) {
|
|
77
|
+
const srcContent = node_fs_1.default.readFileSync(desired.sourcePath, 'utf8');
|
|
78
|
+
const transformed = (0, content_replacements_1.applyContentReplacementsToBuffer)(srcContent, desired.contentReplacements);
|
|
79
|
+
srcHash = (0, utils_1.hashBuffer)(transformed);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
srcHash = await (0, utils_1.hashFile)(desired.sourcePath);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
srcHash = await (0, utils_1.hashFile)(desired.sourcePath);
|
|
87
|
+
}
|
|
88
|
+
const destHash = await (0, utils_1.hashFile)(destPath);
|
|
89
|
+
if (srcHash !== destHash)
|
|
90
|
+
conflictReasons.push('content');
|
|
91
|
+
// Managed-state check
|
|
92
|
+
const isManaged = managedByPath.has(desired.relPath);
|
|
93
|
+
if (desired.managed !== isManaged)
|
|
94
|
+
conflictReasons.push('managed');
|
|
95
|
+
// Gitignore-state check
|
|
96
|
+
const isGitignored = gitignorePaths.has(desired.relPath);
|
|
97
|
+
if (desired.gitignore !== isGitignored)
|
|
98
|
+
conflictReasons.push('gitignore');
|
|
99
|
+
if (conflictReasons.length === 0) {
|
|
100
|
+
result.ok.push({
|
|
101
|
+
status: 'ok',
|
|
102
|
+
relPath: desired.relPath,
|
|
103
|
+
outputDir,
|
|
104
|
+
desired,
|
|
105
|
+
existing: managedByPath.get(desired.relPath),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
result.conflict.push({
|
|
110
|
+
status: 'conflict',
|
|
111
|
+
relPath: desired.relPath,
|
|
112
|
+
outputDir,
|
|
113
|
+
desired,
|
|
114
|
+
existing: managedByPath.get(desired.relPath),
|
|
115
|
+
conflictReasons,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=calculate-diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate-diff.js","sourceRoot":"","sources":["../../src/package/calculate-diff.ts"],"names":[],"mappings":";;;;;AAoBA,sCAoDC;AAxED,+BAA+B;AAC/B,sDAAyB;AACzB,0DAA6B;AAG7B,oDAAmE;AACnE,oCAAmE;AACnE,gDAAyD;AAEzD,iEAA0E;AAE1E;;;;;;;;GAQG;AACI,KAAK,UAAU,aAAa,CACjC,aAA6B,EAC7B,OAAiB,EACjB,GAAY;IAEZ,MAAM,MAAM,GAAe,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EA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AE1E,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;YACb,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,SAAS;YACT,OAAO;YACP,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;YACnB,MAAM,EAAE,UAAU;YAClB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,SAAS;YACT,OAAO;YACP,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;YAC5C,eAAe;SAChB,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { SelectorConfig, OutputConfig } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Merge two SelectorConfig objects across recursion levels.
|
|
4
4
|
* - files: ANDed (intersection); when either is absent, use the other's list
|
|
5
|
+
* - exclude: concatenated (both exclusion lists apply)
|
|
5
6
|
* - contentRegexes: ANDed (both must match)
|
|
6
7
|
* - presets: NOT inherited (caller's presets not forwarded to dependency)
|
|
7
8
|
* - upgrade: each level evaluated independently (not merged)
|
|
@@ -10,7 +11,7 @@ export declare function mergeSelectorConfig(parent: SelectorConfig, child: Selec
|
|
|
10
11
|
/**
|
|
11
12
|
* Merge two OutputConfig objects for recursive extraction.
|
|
12
13
|
* - force, keepExisting, gitignore, managed, dryRun: caller value overrides child
|
|
13
|
-
* - path: concatenated (parent/child)
|
|
14
|
+
* - path: concatenated (parent/child), undefined treated as '.'
|
|
14
15
|
* - symlinks: appended (parent + child)
|
|
15
16
|
* - contentReplacements: appended (parent + child)
|
|
16
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-merge.d.ts","sourceRoot":"","sources":["../../src/package/config-merge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config-merge.d.ts","sourceRoot":"","sources":["../../src/package/config-merge.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,GAAG,cAAc,CAwBjG;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,GAAG,YAAY,CAmBzF"}
|
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.mergeSelectorConfig = mergeSelectorConfig;
|
|
4
7
|
exports.mergeOutputConfig = mergeOutputConfig;
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
5
9
|
/**
|
|
6
10
|
* Merge two SelectorConfig objects across recursion levels.
|
|
7
11
|
* - files: ANDed (intersection); when either is absent, use the other's list
|
|
12
|
+
* - exclude: concatenated (both exclusion lists apply)
|
|
8
13
|
* - contentRegexes: ANDed (both must match)
|
|
9
14
|
* - presets: NOT inherited (caller's presets not forwarded to dependency)
|
|
10
15
|
* - upgrade: each level evaluated independently (not merged)
|
|
11
16
|
*/
|
|
12
17
|
function mergeSelectorConfig(parent, child) {
|
|
13
|
-
const
|
|
14
|
-
|
|
18
|
+
const parentGroups = parent.filePatternGroups ?? (parent.files ? [parent.files] : []);
|
|
19
|
+
const childGroups = child.filePatternGroups ?? (child.files ? [child.files] : []);
|
|
20
|
+
const filePatternGroups = [...parentGroups, ...childGroups];
|
|
21
|
+
const files = filePatternGroups.length > 0
|
|
22
|
+
? [...new Set(filePatternGroups.flat())]
|
|
15
23
|
: (parent.files ?? child.files);
|
|
16
24
|
const contentRegexes = parent.contentRegexes && child.contentRegexes
|
|
17
25
|
? [...parent.contentRegexes, ...child.contentRegexes]
|
|
18
26
|
: (parent.contentRegexes ?? child.contentRegexes);
|
|
27
|
+
const exclude = [...(parent.exclude ?? []), ...(child.exclude ?? [])];
|
|
19
28
|
return {
|
|
20
29
|
files,
|
|
30
|
+
...(filePatternGroups.length > 0 ? { filePatternGroups } : {}),
|
|
31
|
+
exclude,
|
|
21
32
|
contentRegexes,
|
|
22
33
|
presets: child.presets, // not inherited from parent
|
|
23
34
|
upgrade: child.upgrade, // each level independent
|
|
@@ -26,13 +37,18 @@ function mergeSelectorConfig(parent, child) {
|
|
|
26
37
|
/**
|
|
27
38
|
* Merge two OutputConfig objects for recursive extraction.
|
|
28
39
|
* - force, keepExisting, gitignore, managed, dryRun: caller value overrides child
|
|
29
|
-
* - path: concatenated (parent/child)
|
|
40
|
+
* - path: concatenated (parent/child), undefined treated as '.'
|
|
30
41
|
* - symlinks: appended (parent + child)
|
|
31
42
|
* - contentReplacements: appended (parent + child)
|
|
32
43
|
*/
|
|
33
44
|
function mergeOutputConfig(caller, child) {
|
|
45
|
+
const callerPath = caller.path ?? '.';
|
|
46
|
+
const childPath = child.path ?? '.';
|
|
47
|
+
// When childPath is absolute it overrides the inherited path entirely.
|
|
48
|
+
// path.join('.', '/absolute') would strip the leading slash, so we check explicitly.
|
|
49
|
+
const mergedPath = node_path_1.default.isAbsolute(childPath) ? childPath : node_path_1.default.join(callerPath, childPath);
|
|
34
50
|
return {
|
|
35
|
-
path:
|
|
51
|
+
path: mergedPath,
|
|
36
52
|
force: caller.force ?? child.force,
|
|
37
53
|
keepExisting: caller.keepExisting ?? child.keepExisting,
|
|
38
54
|
gitignore: caller.gitignore ?? child.gitignore,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-merge.js","sourceRoot":"","sources":["../../src/package/config-merge.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AE,CAAC;SACrC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NpmdataExtractEntry, ResolvedFile, ProgressEvent } from '../types';
|
|
2
|
+
export type ResolveOptions = {
|
|
3
|
+
cwd: string;
|
|
4
|
+
verbose?: boolean;
|
|
5
|
+
onProgress?: (event: ProgressEvent) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Recursively resolve all entries into a flat list of desired files.
|
|
9
|
+
*
|
|
10
|
+
* Two entry types are handled:
|
|
11
|
+
* - Self-package entry (no `package` field): enumerates files directly from the
|
|
12
|
+
* package context provided by the parent recursion level.
|
|
13
|
+
* - External-package entry (`package` field set): installs the package, reads its
|
|
14
|
+
* npmdata.sets, and recurses; when the package has no sets, files are enumerated
|
|
15
|
+
* directly (leaf behaviour).
|
|
16
|
+
*
|
|
17
|
+
* Duplicate (outputDir, relPath) pairs are deduplicated; conflicting managed/gitignore
|
|
18
|
+
* settings for the same destination path throw an error.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveFiles(entries: NpmdataExtractEntry[], options: ResolveOptions): Promise<ResolvedFile[]>;
|
|
21
|
+
//# sourceMappingURL=resolve-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-files.d.ts","sourceRoot":"","sources":["../../src/package/resolve-files.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,mBAAmB,EAGnB,YAAY,EACZ,aAAa,EACd,MAAM,UAAU,CAAC;AAWlB,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC7C,CAAC;AAaF;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,EAAE,EAC9B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,YAAY,EAAE,CAAC,CAgBzB"}
|