components-differ 1.2.3 → 1.2.5
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/create-diff.js +2 -4
- package/dist/extract-imports.js +34 -3
- package/package.json +1 -1
- package/src/create-diff.ts +3 -5
- package/src/extract-imports.ts +34 -3
package/dist/create-diff.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { findComponentFiles, getAliasedPaths,
|
|
1
|
+
import { findComponentFiles, getAliasedPaths, } from "./components.js";
|
|
2
2
|
import { parseFilePath } from "./parse-file-path.js";
|
|
3
3
|
import { extractImportedPackages } from "./extract-imports.js";
|
|
4
4
|
function addFile(output, config, inSrcDir, relativeFilePath, content) {
|
|
5
|
-
|
|
6
|
-
output.files.push(parseFilePath(inSrcDir, config, `./${relativeFilePath}`, content));
|
|
7
|
-
}
|
|
5
|
+
output.files.push(parseFilePath(inSrcDir, config, `./${relativeFilePath}`, content));
|
|
8
6
|
}
|
|
9
7
|
function addDependencies(output, _initialPackageContents, currentPackageContents, usedPackages) {
|
|
10
8
|
const currentPackageJson = JSON.parse(currentPackageContents);
|
package/dist/extract-imports.js
CHANGED
|
@@ -35,8 +35,12 @@ function specifierToPackageName(specifier) {
|
|
|
35
35
|
return slash === -1 ? s : s.slice(0, slash);
|
|
36
36
|
}
|
|
37
37
|
const RE_IMPORT = /(?:import\s+(?:(?:\{[^}]*\}|\*\s+as\s+\w+|\w+)\s+from\s+)?|import\s*)['"]([^'"]+)['"]|require\s*\(\s*['"]([^'"]+)['"]\s*\)|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
38
|
+
/** Matches re-exports: export { ... } from '...', export * from '...', export Name from '...' */
|
|
39
|
+
const RE_EXPORT_FROM = /export\s+(?:\{[^}]*\}|\*|\w+)\s+from\s+['"]([^'"]+)['"]/g;
|
|
40
|
+
/** Matches type-only re-exports: export type { ... } from '...', export type * from '...' */
|
|
41
|
+
const RE_EXPORT_TYPE_FROM = /export\s+type\s+(?:\{[^}]*\}|\*)\s+from\s+['"]([^'"]+)['"]/g;
|
|
38
42
|
/**
|
|
39
|
-
* Collect all package names that are imported or
|
|
43
|
+
* Collect all package names that are imported, required, or re-exported in the given file content.
|
|
40
44
|
*/
|
|
41
45
|
function extractFromContent(content) {
|
|
42
46
|
const packages = new Set();
|
|
@@ -48,6 +52,20 @@ function extractFromContent(content) {
|
|
|
48
52
|
if (pkg)
|
|
49
53
|
packages.add(pkg);
|
|
50
54
|
}
|
|
55
|
+
RE_EXPORT_FROM.lastIndex = 0;
|
|
56
|
+
while ((m = RE_EXPORT_FROM.exec(content)) !== null) {
|
|
57
|
+
const specifier = m[1] ?? "";
|
|
58
|
+
const pkg = specifierToPackageName(specifier);
|
|
59
|
+
if (pkg)
|
|
60
|
+
packages.add(pkg);
|
|
61
|
+
}
|
|
62
|
+
RE_EXPORT_TYPE_FROM.lastIndex = 0;
|
|
63
|
+
while ((m = RE_EXPORT_TYPE_FROM.exec(content)) !== null) {
|
|
64
|
+
const specifier = m[1] ?? "";
|
|
65
|
+
const pkg = specifierToPackageName(specifier);
|
|
66
|
+
if (pkg)
|
|
67
|
+
packages.add(pkg);
|
|
68
|
+
}
|
|
51
69
|
return packages;
|
|
52
70
|
}
|
|
53
71
|
/**
|
|
@@ -74,8 +92,9 @@ export function isPathSpecifier(specifier) {
|
|
|
74
92
|
return false;
|
|
75
93
|
}
|
|
76
94
|
/**
|
|
77
|
-
* Extract all import/require specifiers that are project paths
|
|
78
|
-
* from file content. Used to pull in imported
|
|
95
|
+
* Extract all import/require and export-from specifiers that are project paths
|
|
96
|
+
* (relative or alias) from file content. Used to pull in imported and
|
|
97
|
+
* re-exported files into the registry.
|
|
79
98
|
*/
|
|
80
99
|
export function extractPathSpecifiers(content) {
|
|
81
100
|
const out = [];
|
|
@@ -86,5 +105,17 @@ export function extractPathSpecifiers(content) {
|
|
|
86
105
|
if (isPathSpecifier(specifier))
|
|
87
106
|
out.push(specifier);
|
|
88
107
|
}
|
|
108
|
+
RE_EXPORT_FROM.lastIndex = 0;
|
|
109
|
+
while ((m = RE_EXPORT_FROM.exec(content)) !== null) {
|
|
110
|
+
const specifier = m[1] ?? "";
|
|
111
|
+
if (isPathSpecifier(specifier))
|
|
112
|
+
out.push(specifier);
|
|
113
|
+
}
|
|
114
|
+
RE_EXPORT_TYPE_FROM.lastIndex = 0;
|
|
115
|
+
while ((m = RE_EXPORT_TYPE_FROM.exec(content)) !== null) {
|
|
116
|
+
const specifier = m[1] ?? "";
|
|
117
|
+
if (isPathSpecifier(specifier))
|
|
118
|
+
out.push(specifier);
|
|
119
|
+
}
|
|
89
120
|
return out;
|
|
90
121
|
}
|
package/package.json
CHANGED
package/src/create-diff.ts
CHANGED
|
@@ -36,11 +36,9 @@ function addFile(
|
|
|
36
36
|
relativeFilePath: string,
|
|
37
37
|
content: string,
|
|
38
38
|
): void {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
);
|
|
43
|
-
}
|
|
39
|
+
output.files.push(
|
|
40
|
+
parseFilePath(inSrcDir, config, `./${relativeFilePath}`, content),
|
|
41
|
+
);
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
function addDependencies(
|
package/src/extract-imports.ts
CHANGED
|
@@ -34,8 +34,16 @@ function specifierToPackageName(specifier: string): string | null {
|
|
|
34
34
|
const RE_IMPORT =
|
|
35
35
|
/(?:import\s+(?:(?:\{[^}]*\}|\*\s+as\s+\w+|\w+)\s+from\s+)?|import\s*)['"]([^'"]+)['"]|require\s*\(\s*['"]([^'"]+)['"]\s*\)|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
36
36
|
|
|
37
|
+
/** Matches re-exports: export { ... } from '...', export * from '...', export Name from '...' */
|
|
38
|
+
const RE_EXPORT_FROM =
|
|
39
|
+
/export\s+(?:\{[^}]*\}|\*|\w+)\s+from\s+['"]([^'"]+)['"]/g;
|
|
40
|
+
|
|
41
|
+
/** Matches type-only re-exports: export type { ... } from '...', export type * from '...' */
|
|
42
|
+
const RE_EXPORT_TYPE_FROM =
|
|
43
|
+
/export\s+type\s+(?:\{[^}]*\}|\*)\s+from\s+['"]([^'"]+)['"]/g;
|
|
44
|
+
|
|
37
45
|
/**
|
|
38
|
-
* Collect all package names that are imported or
|
|
46
|
+
* Collect all package names that are imported, required, or re-exported in the given file content.
|
|
39
47
|
*/
|
|
40
48
|
function extractFromContent(content: string): Set<string> {
|
|
41
49
|
const packages = new Set<string>();
|
|
@@ -46,6 +54,18 @@ function extractFromContent(content: string): Set<string> {
|
|
|
46
54
|
const pkg = specifierToPackageName(specifier);
|
|
47
55
|
if (pkg) packages.add(pkg);
|
|
48
56
|
}
|
|
57
|
+
RE_EXPORT_FROM.lastIndex = 0;
|
|
58
|
+
while ((m = RE_EXPORT_FROM.exec(content)) !== null) {
|
|
59
|
+
const specifier = m[1] ?? "";
|
|
60
|
+
const pkg = specifierToPackageName(specifier);
|
|
61
|
+
if (pkg) packages.add(pkg);
|
|
62
|
+
}
|
|
63
|
+
RE_EXPORT_TYPE_FROM.lastIndex = 0;
|
|
64
|
+
while ((m = RE_EXPORT_TYPE_FROM.exec(content)) !== null) {
|
|
65
|
+
const specifier = m[1] ?? "";
|
|
66
|
+
const pkg = specifierToPackageName(specifier);
|
|
67
|
+
if (pkg) packages.add(pkg);
|
|
68
|
+
}
|
|
49
69
|
return packages;
|
|
50
70
|
}
|
|
51
71
|
|
|
@@ -72,8 +92,9 @@ export function isPathSpecifier(specifier: string): boolean {
|
|
|
72
92
|
}
|
|
73
93
|
|
|
74
94
|
/**
|
|
75
|
-
* Extract all import/require specifiers that are project paths
|
|
76
|
-
* from file content. Used to pull in imported
|
|
95
|
+
* Extract all import/require and export-from specifiers that are project paths
|
|
96
|
+
* (relative or alias) from file content. Used to pull in imported and
|
|
97
|
+
* re-exported files into the registry.
|
|
77
98
|
*/
|
|
78
99
|
export function extractPathSpecifiers(content: string): string[] {
|
|
79
100
|
const out: string[] = [];
|
|
@@ -83,5 +104,15 @@ export function extractPathSpecifiers(content: string): string[] {
|
|
|
83
104
|
const specifier = (m[1] ?? m[2] ?? m[3]) ?? "";
|
|
84
105
|
if (isPathSpecifier(specifier)) out.push(specifier);
|
|
85
106
|
}
|
|
107
|
+
RE_EXPORT_FROM.lastIndex = 0;
|
|
108
|
+
while ((m = RE_EXPORT_FROM.exec(content)) !== null) {
|
|
109
|
+
const specifier = m[1] ?? "";
|
|
110
|
+
if (isPathSpecifier(specifier)) out.push(specifier);
|
|
111
|
+
}
|
|
112
|
+
RE_EXPORT_TYPE_FROM.lastIndex = 0;
|
|
113
|
+
while ((m = RE_EXPORT_TYPE_FROM.exec(content)) !== null) {
|
|
114
|
+
const specifier = m[1] ?? "";
|
|
115
|
+
if (isPathSpecifier(specifier)) out.push(specifier);
|
|
116
|
+
}
|
|
86
117
|
return out;
|
|
87
118
|
}
|