@gtkx/config 2.0.0-beta.11 → 2.0.0-beta.12
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/README.md +2 -2
- package/dist/builtin-elements.d.ts +11 -0
- package/dist/builtin-elements.d.ts.map +1 -0
- package/dist/builtin-elements.js +329 -0
- package/dist/builtin-elements.js.map +1 -0
- package/dist/config-dependencies.d.ts +5 -3
- package/dist/config-dependencies.d.ts.map +1 -1
- package/dist/config-dependencies.js +54 -22
- package/dist/config-dependencies.js.map +1 -1
- package/dist/config-error.d.ts.map +1 -1
- package/dist/config-error.js.map +1 -1
- package/dist/config-reloader.d.ts.map +1 -1
- package/dist/config-reloader.js +2 -8
- package/dist/config-reloader.js.map +1 -1
- package/dist/config-source.d.ts +3 -1
- package/dist/config-source.d.ts.map +1 -1
- package/dist/config-source.js +17 -2
- package/dist/config-source.js.map +1 -1
- package/dist/config.d.ts +34 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +56 -2
- package/dist/config.js.map +1 -1
- package/dist/deploy.d.ts +64 -6
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +168 -10
- package/dist/deploy.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/internal.js.map +1 -1
- package/dist/loader.d.ts +2 -0
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +15 -20
- package/dist/loader.js.map +1 -1
- package/dist/resource-base-path.d.ts.map +1 -1
- package/dist/schema-text.d.ts.map +1 -1
- package/dist/user-event-signals.d.ts.map +1 -1
- package/dist/virtual.d.ts +1 -1
- package/dist/virtual.d.ts.map +1 -1
- package/dist/virtual.js +3 -2
- package/dist/virtual.js.map +1 -1
- package/dist/vite-plugin.d.ts +2 -0
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +4 -3
- package/dist/vite-plugin.js.map +1 -1
- package/dist/vite-root.d.ts.map +1 -1
- package/package.json +14 -29
- package/src/builtin-elements.ts +338 -0
- package/src/config-dependencies.ts +61 -27
- package/src/config-error.ts +5 -3
- package/src/config-reloader.ts +2 -11
- package/src/config-source.ts +25 -2
- package/src/config.ts +65 -4
- package/src/deploy.ts +204 -25
- package/src/index.ts +9 -2
- package/src/internal.ts +2 -2
- package/src/loader.ts +24 -29
- package/src/virtual.ts +5 -4
- package/src/vite-plugin.ts +9 -2
- package/dist/static-dependencies.d.ts +0 -3
- package/dist/static-dependencies.d.ts.map +0 -1
- package/dist/static-dependencies.js +0 -350
- package/dist/static-dependencies.js.map +0 -1
- package/src/static-dependencies.ts +0 -464
package/src/index.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
export { type Config, defineConfig, mergeConfig, type ResolvedConfig } from "./config.ts";
|
|
2
|
-
export {
|
|
1
|
+
export { type Config, defineConfig, type ElementConfigOptions, mergeConfig, type ResolvedConfig } from "./config.ts";
|
|
2
|
+
export {
|
|
3
|
+
type DeployDesktopActionOptions,
|
|
4
|
+
type DeployExtraFileOptions,
|
|
5
|
+
type DeployFileAssociationOptions,
|
|
6
|
+
type DeployNodeOptions,
|
|
7
|
+
type DeployReleaseOptions,
|
|
8
|
+
type DeployScreenshotOptions,
|
|
9
|
+
} from "./deploy.ts";
|
|
3
10
|
export { type ConfigLoader, type LoadedConfig, loadConfig } from "./loader.ts";
|
package/src/internal.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { configDependenciesFor } from "./config-dependencies.ts";
|
|
1
|
+
export { configDependenciesFor, loadConfigModule } from "./config-dependencies.ts";
|
|
2
2
|
export { createConfigReloader } from "./config-reloader.ts";
|
|
3
|
+
export { configCandidatePaths } from "./config-source.ts";
|
|
3
4
|
export type { McpSettings, ResolvedReactCompilerOptions } from "./config.ts";
|
|
4
5
|
export {
|
|
5
6
|
APPLICATION_ID_MAX_LENGTH,
|
|
@@ -17,4 +18,3 @@ export { createConfigLoader } from "./loader.ts";
|
|
|
17
18
|
export { assertSupportedNodeVersion, DEFAULT_NODE_VERSION, MINIMUM_NODE_VERSION } from "./node-version.ts";
|
|
18
19
|
export { resourceBasePath } from "./resource-base-path.ts";
|
|
19
20
|
export { viteProjectRoot } from "./vite-root.ts";
|
|
20
|
-
export { SUPPORTED_EXTENSIONS as CONFIG_EXTENSIONS } from "c12";
|
package/src/loader.ts
CHANGED
|
@@ -3,19 +3,14 @@ import { loadConfig as loadConfigFile } from "c12";
|
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { relative, resolve } from "node:path";
|
|
5
5
|
import {
|
|
6
|
+
addConfigSource,
|
|
6
7
|
captureConfigDependencies,
|
|
8
|
+
createConfigImporter,
|
|
7
9
|
setConfigDependencies,
|
|
8
|
-
transformConfigModule,
|
|
9
10
|
} from "./config-dependencies.ts";
|
|
10
11
|
import { missingConfigFileError } from "./config-error.ts";
|
|
11
12
|
import { type ConfigResolutionOptions, localConfigSourcePath } from "./config-source.ts";
|
|
12
|
-
import {
|
|
13
|
-
type Config,
|
|
14
|
-
graduatedFutureKeys,
|
|
15
|
-
resolveConfig,
|
|
16
|
-
type ResolvedConfig,
|
|
17
|
-
validateConfig,
|
|
18
|
-
} from "./config.ts";
|
|
13
|
+
import { type Config, graduatedFutureKeys, resolveConfig, type ResolvedConfig, validateConfig } from "./config.ts";
|
|
19
14
|
import { assertSupportedNodeVersion } from "./node-version.ts";
|
|
20
15
|
|
|
21
16
|
/** Result of loading a project's `gtkx.config.ts` file. */
|
|
@@ -35,6 +30,8 @@ type LoadConfigOptions = {
|
|
|
35
30
|
* top-level values, and the name is passed to a config authored as a function.
|
|
36
31
|
*/
|
|
37
32
|
mode?: string | undefined;
|
|
33
|
+
/** Whether to report graduated future flags; supervising processes can own these warnings. Defaults to true. */
|
|
34
|
+
shouldWarnGraduatedFuture?: boolean | undefined;
|
|
38
35
|
} & Partial<Record<"configFile", string | undefined>>;
|
|
39
36
|
|
|
40
37
|
/** Reads a project's configuration once per directory, caching what it loads and what it resolves. */
|
|
@@ -45,13 +42,18 @@ type ConfigLoader = {
|
|
|
45
42
|
resolve: (cwd: string) => Promise<ResolvedConfig>;
|
|
46
43
|
};
|
|
47
44
|
|
|
48
|
-
const GRADUATED_FUTURE_ENV = "GTKX_GRADUATED_FUTURE_SHOWN";
|
|
49
45
|
const graduatedFutureWarnings: Map<string, string> = new Map();
|
|
50
46
|
|
|
51
47
|
const rejectMissingLocalConfig = (source: string, options: ConfigResolutionOptions): undefined => {
|
|
52
48
|
const path = localConfigSourcePath(source, options);
|
|
53
49
|
|
|
54
|
-
if (path
|
|
50
|
+
if (path === undefined) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
addConfigSource(path);
|
|
55
|
+
|
|
56
|
+
if (!existsSync(path)) {
|
|
55
57
|
throw new Error(`Extended configuration does not exist at ${path}`);
|
|
56
58
|
}
|
|
57
59
|
};
|
|
@@ -86,16 +88,11 @@ const warnGraduatedFuture = (config: unknown, root: string): void => {
|
|
|
86
88
|
const keys = graduatedFutureKeys(config);
|
|
87
89
|
const signature = keys.join(",");
|
|
88
90
|
|
|
89
|
-
if (
|
|
90
|
-
keys.length === 0 ||
|
|
91
|
-
graduatedFutureWarnings.get(root) === signature ||
|
|
92
|
-
process.env[GRADUATED_FUTURE_ENV] === signature
|
|
93
|
-
) {
|
|
91
|
+
if (keys.length === 0 || graduatedFutureWarnings.get(root) === signature) {
|
|
94
92
|
return;
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
graduatedFutureWarnings.set(root, signature);
|
|
98
|
-
process.env[GRADUATED_FUTURE_ENV] = signature;
|
|
99
96
|
warn(`GTKX 2 ignores graduated future flags: ${keys.join(", ")}. Remove them from gtkx.config.ts.`);
|
|
100
97
|
};
|
|
101
98
|
|
|
@@ -119,24 +116,20 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
|
|
|
119
116
|
packageJson: false,
|
|
120
117
|
omit$Keys: true,
|
|
121
118
|
context: { mode: options.mode },
|
|
122
|
-
|
|
119
|
+
jiti: createConfigImporter(),
|
|
123
120
|
resolve: rejectMissingLocalConfig,
|
|
124
121
|
...(requestedConfigFile !== undefined && { configFile: requestedConfigFile }),
|
|
125
|
-
...(
|
|
126
|
-
})
|
|
122
|
+
...(options.mode !== undefined && { envName: options.mode }),
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
127
125
|
const result = captured.value;
|
|
128
126
|
|
|
129
127
|
const configFile = result.configFile;
|
|
130
128
|
const root = result.cwd ?? searched;
|
|
131
|
-
const layerFiles = (result.layers ?? [])
|
|
132
|
-
.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const dependencies = [
|
|
136
|
-
...(configFile === undefined ? [] : [configFile]),
|
|
137
|
-
...layerFiles,
|
|
138
|
-
...captured.dependencies,
|
|
139
|
-
];
|
|
129
|
+
const layerFiles = (result.layers ?? []).flatMap((layer) =>
|
|
130
|
+
layer.configFile === undefined ? [] : [resolve(layer.cwd ?? root, layer.configFile)],
|
|
131
|
+
);
|
|
132
|
+
const dependencies = [...(configFile === undefined ? [] : [configFile]), ...layerFiles, ...captured.dependencies];
|
|
140
133
|
|
|
141
134
|
return withConfigDependencies(dependencies, () => {
|
|
142
135
|
if (configFile === undefined || !existsSync(resolve(searched, configFile))) {
|
|
@@ -145,7 +138,9 @@ const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise
|
|
|
145
138
|
|
|
146
139
|
const config = result.config;
|
|
147
140
|
validateConfig(config, configFile);
|
|
148
|
-
|
|
141
|
+
if (options.shouldWarnGraduatedFuture !== false) {
|
|
142
|
+
warnGraduatedFuture(config, root);
|
|
143
|
+
}
|
|
149
144
|
|
|
150
145
|
const loaded = {
|
|
151
146
|
config,
|
package/src/virtual.ts
CHANGED
|
@@ -4,20 +4,21 @@ import { resourceBasePath } from "./resource-base-path.ts";
|
|
|
4
4
|
const GTKX_CONFIG_VIRTUAL_ID = "virtual:gtkx-config";
|
|
5
5
|
const RESOLVED_GTKX_CONFIG_VIRTUAL_ID = `\0${GTKX_CONFIG_VIRTUAL_ID}`;
|
|
6
6
|
|
|
7
|
-
const renderConfigModule = (config: ResolvedConfig): string => {
|
|
7
|
+
const renderConfigModule = (config: ResolvedConfig, localeDir: string | null = null): string => {
|
|
8
8
|
const lazyJson = JSON.stringify(Object.fromEntries(config.lazyElements.map((type) => [type, { isLazy: true }])));
|
|
9
9
|
|
|
10
10
|
const behaviorImports =
|
|
11
11
|
config.elements === null
|
|
12
12
|
? []
|
|
13
13
|
: [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
'import { mergeElementConfigs } from "@gtkx/react/config";',
|
|
15
|
+
`import __elementBehaviors from ${JSON.stringify(config.elements)};`,
|
|
16
|
+
];
|
|
17
17
|
|
|
18
18
|
return [
|
|
19
19
|
...behaviorImports,
|
|
20
20
|
`export const applicationId = ${JSON.stringify(config.applicationId)};`,
|
|
21
|
+
`export const localeDir = ${JSON.stringify(localeDir)};`,
|
|
21
22
|
`export const resourceBasePath = ${JSON.stringify(resourceBasePath(config.applicationId))};`,
|
|
22
23
|
`export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,
|
|
23
24
|
config.elements === null
|
package/src/vite-plugin.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Plugin, UserConfig } from "vite";
|
|
2
|
+
import { resolve } from "node:path";
|
|
2
3
|
import { type ConfigLoader, createConfigLoader } from "./loader.ts";
|
|
3
4
|
import { GTKX_CONFIG_VIRTUAL_ID, renderConfigModule, RESOLVED_GTKX_CONFIG_VIRTUAL_ID } from "./virtual.ts";
|
|
4
5
|
import { viteProjectRoot } from "./vite-root.ts";
|
|
@@ -17,12 +18,16 @@ const loadVirtualModule = async (
|
|
|
17
18
|
id: string,
|
|
18
19
|
loadConfig: ConfigLoader,
|
|
19
20
|
state: PluginState,
|
|
21
|
+
localeDir: string | null | undefined,
|
|
20
22
|
): Promise<string | undefined> => {
|
|
21
23
|
if (id !== RESOLVED_GTKX_CONFIG_VIRTUAL_ID) {
|
|
22
24
|
return undefined;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
return renderConfigModule(
|
|
27
|
+
return renderConfigModule(
|
|
28
|
+
await loadConfig.resolve(state.root),
|
|
29
|
+
localeDir == null ? null : resolve(state.root, localeDir),
|
|
30
|
+
);
|
|
26
31
|
};
|
|
27
32
|
|
|
28
33
|
/**
|
|
@@ -34,6 +39,8 @@ const createConfigPlugin = (options: {
|
|
|
34
39
|
name: string;
|
|
35
40
|
/** Loader the configuration is resolved through, defaulting to a fresh caching loader. */
|
|
36
41
|
loadConfig?: ConfigLoader;
|
|
42
|
+
/** Catalog directory for development or tests, resolved relative to the project root. */
|
|
43
|
+
localeDir?: string | null | undefined;
|
|
37
44
|
/** Extra Vite configuration contributed from the plugin's `config` hook, given the user's own configuration. */
|
|
38
45
|
config?: (config: UserConfig) => Omit<UserConfig, "plugins">;
|
|
39
46
|
}): Plugin => {
|
|
@@ -53,7 +60,7 @@ const createConfigPlugin = (options: {
|
|
|
53
60
|
},
|
|
54
61
|
load: {
|
|
55
62
|
filter: { id: RESOLVED_VIRTUAL_ID_RE },
|
|
56
|
-
handler: (id: string) => loadVirtualModule(id, loadConfig, state),
|
|
63
|
+
handler: (id: string) => loadVirtualModule(id, loadConfig, state, options.localeDir),
|
|
57
64
|
},
|
|
58
65
|
};
|
|
59
66
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"static-dependencies.d.ts","sourceRoot":"","sources":["../src/static-dependencies.ts"],"names":[],"mappings":"AAqbA,QAAA,MAAM,yBAAyB,GAC3B,YAAY,MAAM,EAClB,mBAAiC,EACjC,mBAAgC,KACjC,MAAM,EAoBR,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
import { parseSync, traverse, types } from "@babel/core";
|
|
2
|
-
import { parseJSON, parseJSON5, parseJSONC, parseTOML, parseYAML } from "confbox";
|
|
3
|
-
import { createJiti } from "jiti";
|
|
4
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
-
import { basename, dirname, extname, isAbsolute, join, resolve, sep } from "node:path";
|
|
6
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
-
import { localConfigSourcePath } from "./config-source.js";
|
|
8
|
-
const MODULE_EXTENSIONS = new Set([
|
|
9
|
-
".cjs",
|
|
10
|
-
".cts",
|
|
11
|
-
".js",
|
|
12
|
-
".mjs",
|
|
13
|
-
".mts",
|
|
14
|
-
".ts",
|
|
15
|
-
]);
|
|
16
|
-
const RESOLVABLE_EXTENSIONS = [
|
|
17
|
-
".js",
|
|
18
|
-
".ts",
|
|
19
|
-
".mjs",
|
|
20
|
-
".cjs",
|
|
21
|
-
".mts",
|
|
22
|
-
".cts",
|
|
23
|
-
".json",
|
|
24
|
-
".jsonc",
|
|
25
|
-
".json5",
|
|
26
|
-
".yaml",
|
|
27
|
-
".yml",
|
|
28
|
-
".toml",
|
|
29
|
-
];
|
|
30
|
-
const JAVASCRIPT_FALLBACKS = {
|
|
31
|
-
".cjs": [".cts"],
|
|
32
|
-
".js": [".ts"],
|
|
33
|
-
".jsx": [".tsx"],
|
|
34
|
-
".mjs": [".mts"],
|
|
35
|
-
};
|
|
36
|
-
const DATA_PARSERS = {
|
|
37
|
-
".json": parseJSON,
|
|
38
|
-
".json5": parseJSON5,
|
|
39
|
-
".jsonc": parseJSONC,
|
|
40
|
-
".toml": parseTOML,
|
|
41
|
-
".yaml": parseYAML,
|
|
42
|
-
".yml": parseYAML,
|
|
43
|
-
};
|
|
44
|
-
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45
|
-
const parserPlugins = (path) => {
|
|
46
|
-
const extension = extname(path).toLowerCase();
|
|
47
|
-
return [
|
|
48
|
-
"decorators",
|
|
49
|
-
...([".cts", ".mts", ".ts"].includes(extension) ? ["typescript"] : []),
|
|
50
|
-
];
|
|
51
|
-
};
|
|
52
|
-
function expressionSources(value) {
|
|
53
|
-
if (types.isStringLiteral(value)) {
|
|
54
|
-
return [value.value];
|
|
55
|
-
}
|
|
56
|
-
if (types.isArrayExpression(value)) {
|
|
57
|
-
return value.elements.flatMap((element) => types.isExpression(element) ? expressionSources(element) : []);
|
|
58
|
-
}
|
|
59
|
-
return types.isObjectExpression(value)
|
|
60
|
-
? value.properties.flatMap((property) => sourcePropertySources(property))
|
|
61
|
-
: [];
|
|
62
|
-
}
|
|
63
|
-
const isNamedProperty = (property, name) => (types.isIdentifier(property.key) && property.key.name === name) ||
|
|
64
|
-
(types.isStringLiteral(property.key) && property.key.value === name);
|
|
65
|
-
function sourcePropertySources(property) {
|
|
66
|
-
return types.isObjectProperty(property) &&
|
|
67
|
-
isNamedProperty(property, "source") &&
|
|
68
|
-
types.isExpression(property.value)
|
|
69
|
-
? expressionSources(property.value)
|
|
70
|
-
: [];
|
|
71
|
-
}
|
|
72
|
-
const extendsSources = (value) => expressionSources(value);
|
|
73
|
-
const isExtendsProperty = (property) => isNamedProperty(property, "extends");
|
|
74
|
-
const parseModule = (path) => {
|
|
75
|
-
try {
|
|
76
|
-
return parseSync(readFileSync(path, "utf8"), {
|
|
77
|
-
ast: true,
|
|
78
|
-
babelrc: false,
|
|
79
|
-
configFile: false,
|
|
80
|
-
filename: path,
|
|
81
|
-
parserOpts: { allowReturnOutsideFunction: true, plugins: parserPlugins(path) },
|
|
82
|
-
sourceType: "unambiguous",
|
|
83
|
-
}) ?? undefined;
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
const addSource = (sources, source) => {
|
|
90
|
-
if (source !== null && source !== undefined) {
|
|
91
|
-
sources.add(source.value);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const requireSource = (call) => types.isIdentifier(call.callee, { name: "require" }) && types.isStringLiteral(call.arguments[0])
|
|
95
|
-
? call.arguments[0]
|
|
96
|
-
: undefined;
|
|
97
|
-
const importEqualsSource = (declaration) => {
|
|
98
|
-
const { moduleReference } = declaration;
|
|
99
|
-
return types.isTSExternalModuleReference(moduleReference) ? moduleReference.expression : undefined;
|
|
100
|
-
};
|
|
101
|
-
const propertySources = (property) => isExtendsProperty(property) && types.isExpression(property.value)
|
|
102
|
-
? extendsSources(property.value)
|
|
103
|
-
: [];
|
|
104
|
-
const collectModuleSources = (ast) => {
|
|
105
|
-
const sources = new Set();
|
|
106
|
-
const extended = new Set();
|
|
107
|
-
traverse(ast, {
|
|
108
|
-
CallExpression: (nodePath) => {
|
|
109
|
-
addSource(sources, requireSource(nodePath.node));
|
|
110
|
-
},
|
|
111
|
-
ExportAllDeclaration: (nodePath) => {
|
|
112
|
-
addSource(sources, nodePath.node.source);
|
|
113
|
-
},
|
|
114
|
-
ExportNamedDeclaration: (nodePath) => {
|
|
115
|
-
addSource(sources, nodePath.node.source);
|
|
116
|
-
},
|
|
117
|
-
ImportDeclaration: (nodePath) => {
|
|
118
|
-
addSource(sources, nodePath.node.source);
|
|
119
|
-
},
|
|
120
|
-
ImportExpression: (nodePath) => {
|
|
121
|
-
const { source } = nodePath.node;
|
|
122
|
-
addSource(sources, types.isStringLiteral(source) ? source : undefined);
|
|
123
|
-
},
|
|
124
|
-
ObjectProperty: (nodePath) => {
|
|
125
|
-
for (const source of propertySources(nodePath.node)) {
|
|
126
|
-
sources.add(source);
|
|
127
|
-
extended.add(source);
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
TSImportEqualsDeclaration: (nodePath) => {
|
|
131
|
-
addSource(sources, importEqualsSource(nodePath.node));
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
return { all: [...sources], extended: [...extended] };
|
|
135
|
-
};
|
|
136
|
-
const moduleSources = (path) => {
|
|
137
|
-
const ast = parseModule(path);
|
|
138
|
-
return ast === undefined ? { all: [], extended: [] } : collectModuleSources(ast);
|
|
139
|
-
};
|
|
140
|
-
function parsedExtendsSources(value) {
|
|
141
|
-
if (typeof value === "string") {
|
|
142
|
-
return [value];
|
|
143
|
-
}
|
|
144
|
-
if (Array.isArray(value)) {
|
|
145
|
-
return value.flatMap((item) => parsedExtendsSources(item));
|
|
146
|
-
}
|
|
147
|
-
return objectExtendsSources(value);
|
|
148
|
-
}
|
|
149
|
-
const objectExtendsSources = (value) => {
|
|
150
|
-
if (typeof value !== "object" || value === null) {
|
|
151
|
-
return [];
|
|
152
|
-
}
|
|
153
|
-
return "source" in value ? parsedExtendsSources(value.source) : [];
|
|
154
|
-
};
|
|
155
|
-
const configExtendsSources = (value) => {
|
|
156
|
-
if (typeof value !== "object" || value === null) {
|
|
157
|
-
return [];
|
|
158
|
-
}
|
|
159
|
-
return "extends" in value ? parsedExtendsSources(value.extends) : [];
|
|
160
|
-
};
|
|
161
|
-
const dataSources = (path) => {
|
|
162
|
-
const parser = DATA_PARSERS[extname(path).toLowerCase()];
|
|
163
|
-
if (parser === undefined) {
|
|
164
|
-
return [];
|
|
165
|
-
}
|
|
166
|
-
try {
|
|
167
|
-
return configExtendsSources(parser(readFileSync(path, "utf8")));
|
|
168
|
-
}
|
|
169
|
-
catch {
|
|
170
|
-
return [];
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
const extensionCandidates = (path) => {
|
|
174
|
-
const extension = extname(path).toLowerCase();
|
|
175
|
-
if (extension.length === 0) {
|
|
176
|
-
return RESOLVABLE_EXTENSIONS.map((candidate) => `${path}${candidate}`);
|
|
177
|
-
}
|
|
178
|
-
const stem = path.slice(0, -extension.length);
|
|
179
|
-
return (JAVASCRIPT_FALLBACKS[extension] ?? []).map((candidate) => `${stem}${candidate}`);
|
|
180
|
-
};
|
|
181
|
-
const targetCandidates = (target, configName) => {
|
|
182
|
-
const extension = extname(target);
|
|
183
|
-
if (extension.length > 0) {
|
|
184
|
-
return [target, ...extensionCandidates(target)];
|
|
185
|
-
}
|
|
186
|
-
return [
|
|
187
|
-
target,
|
|
188
|
-
...extensionCandidates(target),
|
|
189
|
-
join(target, configName),
|
|
190
|
-
...RESOLVABLE_EXTENSIONS.map((candidate) => join(target, `index${candidate}`)),
|
|
191
|
-
];
|
|
192
|
-
};
|
|
193
|
-
const localSourceTarget = (source, importer) => {
|
|
194
|
-
const clean = source.split(/[?#]/u, 1)[0] ?? "";
|
|
195
|
-
if (clean.startsWith("file:")) {
|
|
196
|
-
return fileURLToPath(clean);
|
|
197
|
-
}
|
|
198
|
-
if (!isAbsolute(clean) && !clean.startsWith(".")) {
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
return resolve(dirname(importer), clean);
|
|
202
|
-
};
|
|
203
|
-
const unresolvedCandidates = (source, importer, configName) => {
|
|
204
|
-
const target = localSourceTarget(source, importer);
|
|
205
|
-
if (target === undefined) {
|
|
206
|
-
return [];
|
|
207
|
-
}
|
|
208
|
-
return targetCandidates(target, configName);
|
|
209
|
-
};
|
|
210
|
-
const nearestPackageFile = (importer) => {
|
|
211
|
-
let directory = dirname(importer);
|
|
212
|
-
let previous = "";
|
|
213
|
-
while (directory !== previous) {
|
|
214
|
-
const candidate = join(directory, "package.json");
|
|
215
|
-
if (existsSync(candidate)) {
|
|
216
|
-
return candidate;
|
|
217
|
-
}
|
|
218
|
-
previous = directory;
|
|
219
|
-
directory = dirname(directory);
|
|
220
|
-
}
|
|
221
|
-
return undefined;
|
|
222
|
-
};
|
|
223
|
-
const readPackageImports = (importer) => {
|
|
224
|
-
const file = nearestPackageFile(importer);
|
|
225
|
-
if (file === undefined) {
|
|
226
|
-
return undefined;
|
|
227
|
-
}
|
|
228
|
-
try {
|
|
229
|
-
const manifest = parseJSON(readFileSync(file, "utf8"));
|
|
230
|
-
return isRecord(manifest) && isRecord(manifest.imports)
|
|
231
|
-
? { file, imports: manifest.imports, root: dirname(file) }
|
|
232
|
-
: undefined;
|
|
233
|
-
}
|
|
234
|
-
catch {
|
|
235
|
-
return undefined;
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
function stringTargets(value) {
|
|
239
|
-
if (typeof value === "string") {
|
|
240
|
-
return [value];
|
|
241
|
-
}
|
|
242
|
-
if (Array.isArray(value)) {
|
|
243
|
-
return value.flatMap((item) => stringTargets(item));
|
|
244
|
-
}
|
|
245
|
-
return isRecord(value)
|
|
246
|
-
? Object.values(value).flatMap((item) => stringTargets(item))
|
|
247
|
-
: [];
|
|
248
|
-
}
|
|
249
|
-
const importPatternMatch = (pattern, source) => {
|
|
250
|
-
if (pattern === source) {
|
|
251
|
-
return "";
|
|
252
|
-
}
|
|
253
|
-
const wildcard = pattern.indexOf("*");
|
|
254
|
-
if (wildcard === -1) {
|
|
255
|
-
return undefined;
|
|
256
|
-
}
|
|
257
|
-
const prefix = pattern.slice(0, wildcard);
|
|
258
|
-
const suffix = pattern.slice(wildcard + 1);
|
|
259
|
-
return source.startsWith(prefix) && source.endsWith(suffix)
|
|
260
|
-
? source.slice(prefix.length, source.length - suffix.length)
|
|
261
|
-
: undefined;
|
|
262
|
-
};
|
|
263
|
-
const packageImportTargets = (source, imports) => Object.entries(imports).flatMap(([pattern, value]) => {
|
|
264
|
-
const match = importPatternMatch(pattern, source);
|
|
265
|
-
return match === undefined
|
|
266
|
-
? []
|
|
267
|
-
: stringTargets(value).map((target) => target.split("*").join(match));
|
|
268
|
-
});
|
|
269
|
-
const packageImportDependencies = (source, importer, configName) => {
|
|
270
|
-
if (!source.startsWith("#")) {
|
|
271
|
-
return [];
|
|
272
|
-
}
|
|
273
|
-
const packageImports = readPackageImports(importer);
|
|
274
|
-
if (packageImports === undefined) {
|
|
275
|
-
return [];
|
|
276
|
-
}
|
|
277
|
-
const targets = packageImportTargets(source, packageImports.imports)
|
|
278
|
-
.filter((target) => target.startsWith("."))
|
|
279
|
-
.flatMap((target) => targetCandidates(resolve(packageImports.root, target), configName));
|
|
280
|
-
return [packageImports.file, ...targets];
|
|
281
|
-
};
|
|
282
|
-
const normalizedResolvedPath = (path) => path.startsWith("file:") ? fileURLToPath(path) : path;
|
|
283
|
-
const resolvedSourcePath = (source, importer, jiti) => {
|
|
284
|
-
try {
|
|
285
|
-
const path = jiti.esmResolve(source, {
|
|
286
|
-
parentURL: pathToFileURL(importer).href,
|
|
287
|
-
try: true,
|
|
288
|
-
});
|
|
289
|
-
return path === undefined ? undefined : normalizedResolvedPath(path);
|
|
290
|
-
}
|
|
291
|
-
catch {
|
|
292
|
-
return undefined;
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
const sourceDependencies = (source, importer, configName, jiti) => {
|
|
296
|
-
const dependency = resolvedSourcePath(source, importer, jiti);
|
|
297
|
-
const packageDependencies = packageImportDependencies(source, importer, configName);
|
|
298
|
-
return dependency === undefined
|
|
299
|
-
? [...unresolvedCandidates(source, importer, configName), ...packageDependencies]
|
|
300
|
-
: [dependency, ...packageDependencies];
|
|
301
|
-
};
|
|
302
|
-
const configLayerDirectory = (path, configName, configRoot) => {
|
|
303
|
-
const segments = configName.split(/[\\/]/u).filter((segment) => segment.length > 0);
|
|
304
|
-
let directory = resolve(path);
|
|
305
|
-
let remaining = segments.length;
|
|
306
|
-
while (remaining > 0) {
|
|
307
|
-
directory = dirname(directory);
|
|
308
|
-
remaining -= 1;
|
|
309
|
-
}
|
|
310
|
-
return resolve(directory, ...segments) === resolve(path) ? directory : resolve(configRoot);
|
|
311
|
-
};
|
|
312
|
-
const c12SourceDependencies = (source, importer, configName, configRoot) => {
|
|
313
|
-
const clean = source.split(/[?#]/u, 1)[0] ?? "";
|
|
314
|
-
const cwd = configLayerDirectory(importer, configName, configRoot);
|
|
315
|
-
const target = localConfigSourcePath(clean, { cwd, configFile: configName });
|
|
316
|
-
return target === undefined ? [] : targetCandidates(target, configName);
|
|
317
|
-
};
|
|
318
|
-
const directDependencies = (path, configName, configRoot) => {
|
|
319
|
-
const module = MODULE_EXTENSIONS.has(extname(path).toLowerCase()) ? moduleSources(path) : undefined;
|
|
320
|
-
const sources = module?.all ?? dataSources(path);
|
|
321
|
-
const extended = module?.extended ?? sources;
|
|
322
|
-
const jiti = createJiti(path, {
|
|
323
|
-
extensions: RESOLVABLE_EXTENSIONS,
|
|
324
|
-
fsCache: false,
|
|
325
|
-
moduleCache: false,
|
|
326
|
-
});
|
|
327
|
-
return [
|
|
328
|
-
...sources.flatMap((source) => sourceDependencies(source, path, configName, jiti)),
|
|
329
|
-
...extended.flatMap((source) => c12SourceDependencies(source, path, configName, configRoot)),
|
|
330
|
-
]
|
|
331
|
-
.filter((dependency) => !dependency.includes(`${sep}node_modules${sep}`));
|
|
332
|
-
};
|
|
333
|
-
const resolveConfigDependencies = (configFile, configName = basename(configFile), configRoot = dirname(configFile)) => {
|
|
334
|
-
const dependencies = new Set();
|
|
335
|
-
const pending = [resolve(configFile)];
|
|
336
|
-
while (pending.length > 0) {
|
|
337
|
-
const path = pending.pop();
|
|
338
|
-
if (path === undefined) {
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
if (dependencies.has(path)) {
|
|
342
|
-
continue;
|
|
343
|
-
}
|
|
344
|
-
dependencies.add(path);
|
|
345
|
-
pending.push(...directDependencies(path, configName, configRoot));
|
|
346
|
-
}
|
|
347
|
-
return [...dependencies];
|
|
348
|
-
};
|
|
349
|
-
export { resolveConfigDependencies };
|
|
350
|
-
//# sourceMappingURL=static-dependencies.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"static-dependencies.js","sourceRoot":"","sources":["../src/static-dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAE,UAAU,EAAa,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,UAA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CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAC9B,UAAkB,EAClB,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,EACjC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,EACxB,EAAE;IACV,MAAM,YAAY,GAAgB,IAAI,GAAG,EAAE,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IAEtC,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAE3B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,MAAM;QACV,CAAC;QAED,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,SAAS;QACb,CAAC;QAED,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC","sourcesContent":["import { parseSync, traverse, types } from \"@babel/core\";\nimport { parseJSON, parseJSON5, parseJSONC, parseTOML, parseYAML } from \"confbox\";\nimport { createJiti, type Jiti } from \"jiti\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { basename, dirname, extname, isAbsolute, join, resolve, sep } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { localConfigSourcePath } from \"./config-source.ts\";\n\nconst MODULE_EXTENSIONS: ReadonlySet<string> = new Set([\n \".cjs\",\n \".cts\",\n \".js\",\n \".mjs\",\n \".mts\",\n \".ts\",\n]);\nconst RESOLVABLE_EXTENSIONS = [\n \".js\",\n \".ts\",\n \".mjs\",\n \".cjs\",\n \".mts\",\n \".cts\",\n \".json\",\n \".jsonc\",\n \".json5\",\n \".yaml\",\n \".yml\",\n \".toml\",\n];\nconst JAVASCRIPT_FALLBACKS: Readonly<Record<string, string[]>> = {\n \".cjs\": [\".cts\"],\n \".js\": [\".ts\"],\n \".jsx\": [\".tsx\"],\n \".mjs\": [\".mts\"],\n};\nconst DATA_PARSERS: Readonly<Record<string, (source: string) => unknown>> = {\n \".json\": parseJSON,\n \".json5\": parseJSON5,\n \".jsonc\": parseJSONC,\n \".toml\": parseTOML,\n \".yaml\": parseYAML,\n \".yml\": parseYAML,\n};\n\ntype PackageImports = { file: string; imports: Record<string, unknown>; root: string };\ntype ModuleSources = { all: string[]; extended: string[] };\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst parserPlugins = (path: string): (\"decorators\" | \"jsx\" | \"typescript\")[] => {\n const extension = extname(path).toLowerCase();\n\n return [\n \"decorators\",\n ...([\".cts\", \".mts\", \".ts\"].includes(extension) ? [\"typescript\" as const] : []),\n ];\n};\n\nfunction expressionSources(value: types.Expression): string[] {\n if (types.isStringLiteral(value)) {\n return [value.value];\n }\n\n if (types.isArrayExpression(value)) {\n return value.elements.flatMap((element) =>\n types.isExpression(element) ? expressionSources(element) : []);\n }\n\n return types.isObjectExpression(value)\n ? value.properties.flatMap((property) => sourcePropertySources(property))\n : [];\n}\n\nconst isNamedProperty = (property: types.ObjectProperty, name: string): boolean =>\n (types.isIdentifier(property.key) && property.key.name === name) ||\n (types.isStringLiteral(property.key) && property.key.value === name);\n\nfunction sourcePropertySources(\n property: types.ObjectMethod | types.ObjectProperty | types.SpreadElement,\n): string[] {\n return types.isObjectProperty(property) &&\n isNamedProperty(property, \"source\") &&\n types.isExpression(property.value)\n ? expressionSources(property.value)\n : [];\n}\n\nconst extendsSources = (value: types.Expression): string[] => expressionSources(value);\n\nconst isExtendsProperty = (property: types.ObjectProperty): boolean =>\n isNamedProperty(property, \"extends\");\n\ntype ParsedModule = NonNullable<ReturnType<typeof parseSync>>;\n\nconst parseModule = (path: string): ParsedModule | undefined => {\n try {\n return parseSync(readFileSync(path, \"utf8\"), {\n ast: true,\n babelrc: false,\n configFile: false,\n filename: path,\n parserOpts: { allowReturnOutsideFunction: true, plugins: parserPlugins(path) },\n sourceType: \"unambiguous\",\n }) ?? undefined;\n } catch {\n return undefined;\n }\n};\n\nconst addSource = (sources: Set<string>, source: types.StringLiteral | null | undefined): void => {\n if (source !== null && source !== undefined) {\n sources.add(source.value);\n }\n};\n\nconst requireSource = (call: types.CallExpression): types.StringLiteral | undefined =>\n types.isIdentifier(call.callee, { name: \"require\" }) && types.isStringLiteral(call.arguments[0])\n ? call.arguments[0]\n : undefined;\n\nconst importEqualsSource = (declaration: types.TSImportEqualsDeclaration): types.StringLiteral | undefined => {\n const { moduleReference } = declaration;\n\n return types.isTSExternalModuleReference(moduleReference) ? moduleReference.expression : undefined;\n};\n\nconst propertySources = (property: types.ObjectProperty): string[] =>\n isExtendsProperty(property) && types.isExpression(property.value)\n ? extendsSources(property.value)\n : [];\n\nconst collectModuleSources = (ast: ParsedModule): ModuleSources => {\n const sources: Set<string> = new Set();\n const extended: Set<string> = new Set();\n\n traverse(ast, {\n CallExpression: (nodePath) => {\n addSource(sources, requireSource(nodePath.node));\n },\n ExportAllDeclaration: (nodePath) => {\n addSource(sources, nodePath.node.source);\n },\n ExportNamedDeclaration: (nodePath) => {\n addSource(sources, nodePath.node.source);\n },\n ImportDeclaration: (nodePath) => {\n addSource(sources, nodePath.node.source);\n },\n ImportExpression: (nodePath) => {\n const { source } = nodePath.node;\n addSource(sources, types.isStringLiteral(source) ? source : undefined);\n },\n ObjectProperty: (nodePath) => {\n for (const source of propertySources(nodePath.node)) {\n sources.add(source);\n extended.add(source);\n }\n },\n TSImportEqualsDeclaration: (nodePath) => {\n addSource(sources, importEqualsSource(nodePath.node));\n },\n });\n\n return { all: [...sources], extended: [...extended] };\n};\n\nconst moduleSources = (path: string): ModuleSources => {\n const ast = parseModule(path);\n\n return ast === undefined ? { all: [], extended: [] } : collectModuleSources(ast);\n};\n\nfunction parsedExtendsSources(value: unknown): string[] {\n if (typeof value === \"string\") {\n return [value];\n }\n\n if (Array.isArray(value)) {\n return value.flatMap((item) => parsedExtendsSources(item));\n }\n\n return objectExtendsSources(value);\n}\n\nconst objectExtendsSources = (value: unknown): string[] => {\n if (typeof value !== \"object\" || value === null) {\n return [];\n }\n\n return \"source\" in value ? parsedExtendsSources(value.source) : [];\n};\n\nconst configExtendsSources = (value: unknown): string[] => {\n if (typeof value !== \"object\" || value === null) {\n return [];\n }\n\n return \"extends\" in value ? parsedExtendsSources(value.extends) : [];\n};\n\nconst dataSources = (path: string): string[] => {\n const parser = DATA_PARSERS[extname(path).toLowerCase()];\n\n if (parser === undefined) {\n return [];\n }\n\n try {\n return configExtendsSources(parser(readFileSync(path, \"utf8\")));\n } catch {\n return [];\n }\n};\n\nconst extensionCandidates = (path: string): string[] => {\n const extension = extname(path).toLowerCase();\n\n if (extension.length === 0) {\n return RESOLVABLE_EXTENSIONS.map((candidate) => `${path}${candidate}`);\n }\n\n const stem = path.slice(0, -extension.length);\n\n return (JAVASCRIPT_FALLBACKS[extension] ?? []).map((candidate) => `${stem}${candidate}`);\n};\n\nconst targetCandidates = (target: string, configName: string): string[] => {\n const extension = extname(target);\n\n if (extension.length > 0) {\n return [target, ...extensionCandidates(target)];\n }\n\n return [\n target,\n ...extensionCandidates(target),\n join(target, configName),\n ...RESOLVABLE_EXTENSIONS.map((candidate) => join(target, `index${candidate}`)),\n ];\n};\n\nconst localSourceTarget = (source: string, importer: string): string | undefined => {\n const clean = source.split(/[?#]/u, 1)[0] ?? \"\";\n\n if (clean.startsWith(\"file:\")) {\n return fileURLToPath(clean);\n }\n\n if (!isAbsolute(clean) && !clean.startsWith(\".\")) {\n return undefined;\n }\n\n return resolve(dirname(importer), clean);\n};\n\nconst unresolvedCandidates = (source: string, importer: string, configName: string): string[] => {\n const target = localSourceTarget(source, importer);\n\n if (target === undefined) {\n return [];\n }\n\n return targetCandidates(target, configName);\n};\n\nconst nearestPackageFile = (importer: string): string | undefined => {\n let directory = dirname(importer);\n let previous = \"\";\n\n while (directory !== previous) {\n const candidate = join(directory, \"package.json\");\n\n if (existsSync(candidate)) {\n return candidate;\n }\n\n previous = directory;\n directory = dirname(directory);\n }\n\n return undefined;\n};\n\nconst readPackageImports = (importer: string): PackageImports | undefined => {\n const file = nearestPackageFile(importer);\n\n if (file === undefined) {\n return undefined;\n }\n\n try {\n const manifest = parseJSON(readFileSync(file, \"utf8\"));\n\n return isRecord(manifest) && isRecord(manifest.imports)\n ? { file, imports: manifest.imports, root: dirname(file) }\n : undefined;\n } catch {\n return undefined;\n }\n};\n\nfunction stringTargets(value: unknown): string[] {\n if (typeof value === \"string\") {\n return [value];\n }\n\n if (Array.isArray(value)) {\n return value.flatMap((item) => stringTargets(item));\n }\n\n return isRecord(value)\n ? Object.values(value).flatMap((item) => stringTargets(item))\n : [];\n}\n\nconst importPatternMatch = (pattern: string, source: string): string | undefined => {\n if (pattern === source) {\n return \"\";\n }\n\n const wildcard = pattern.indexOf(\"*\");\n\n if (wildcard === -1) {\n return undefined;\n }\n\n const prefix = pattern.slice(0, wildcard);\n const suffix = pattern.slice(wildcard + 1);\n\n return source.startsWith(prefix) && source.endsWith(suffix)\n ? source.slice(prefix.length, source.length - suffix.length)\n : undefined;\n};\n\nconst packageImportTargets = (source: string, imports: Record<string, unknown>): string[] =>\n Object.entries(imports).flatMap(([pattern, value]) => {\n const match = importPatternMatch(pattern, source);\n\n return match === undefined\n ? []\n : stringTargets(value).map((target) => target.split(\"*\").join(match));\n });\n\nconst packageImportDependencies = (source: string, importer: string, configName: string): string[] => {\n if (!source.startsWith(\"#\")) {\n return [];\n }\n\n const packageImports = readPackageImports(importer);\n\n if (packageImports === undefined) {\n return [];\n }\n\n const targets = packageImportTargets(source, packageImports.imports)\n .filter((target) => target.startsWith(\".\"))\n .flatMap((target) => targetCandidates(resolve(packageImports.root, target), configName));\n\n return [packageImports.file, ...targets];\n};\n\nconst normalizedResolvedPath = (path: string): string =>\n path.startsWith(\"file:\") ? fileURLToPath(path) : path;\n\nconst resolvedSourcePath = (source: string, importer: string, jiti: Jiti): string | undefined => {\n try {\n const path = jiti.esmResolve(source, {\n parentURL: pathToFileURL(importer).href,\n try: true,\n });\n\n return path === undefined ? undefined : normalizedResolvedPath(path);\n } catch {\n return undefined;\n }\n};\n\nconst sourceDependencies = (\n source: string,\n importer: string,\n configName: string,\n jiti: Jiti,\n): string[] => {\n const dependency = resolvedSourcePath(source, importer, jiti);\n const packageDependencies = packageImportDependencies(source, importer, configName);\n\n return dependency === undefined\n ? [...unresolvedCandidates(source, importer, configName), ...packageDependencies]\n : [dependency, ...packageDependencies];\n};\n\nconst configLayerDirectory = (path: string, configName: string, configRoot: string): string => {\n const segments = configName.split(/[\\\\/]/u).filter((segment) => segment.length > 0);\n let directory = resolve(path);\n let remaining = segments.length;\n\n while (remaining > 0) {\n directory = dirname(directory);\n remaining -= 1;\n }\n\n return resolve(directory, ...segments) === resolve(path) ? directory : resolve(configRoot);\n};\n\nconst c12SourceDependencies = (\n source: string,\n importer: string,\n configName: string,\n configRoot: string,\n): string[] => {\n const clean = source.split(/[?#]/u, 1)[0] ?? \"\";\n\n const cwd = configLayerDirectory(importer, configName, configRoot);\n const target = localConfigSourcePath(clean, { cwd, configFile: configName });\n\n return target === undefined ? [] : targetCandidates(target, configName);\n};\n\nconst directDependencies = (path: string, configName: string, configRoot: string): string[] => {\n const module = MODULE_EXTENSIONS.has(extname(path).toLowerCase()) ? moduleSources(path) : undefined;\n const sources = module?.all ?? dataSources(path);\n const extended = module?.extended ?? sources;\n const jiti = createJiti(path, {\n extensions: RESOLVABLE_EXTENSIONS,\n fsCache: false,\n moduleCache: false,\n });\n\n return [\n ...sources.flatMap((source) => sourceDependencies(source, path, configName, jiti)),\n ...extended.flatMap((source) => c12SourceDependencies(source, path, configName, configRoot)),\n ]\n .filter((dependency) => !dependency.includes(`${sep}node_modules${sep}`));\n};\n\nconst resolveConfigDependencies = (\n configFile: string,\n configName = basename(configFile),\n configRoot = dirname(configFile),\n): string[] => {\n const dependencies: Set<string> = new Set();\n const pending = [resolve(configFile)];\n\n while (pending.length > 0) {\n const path = pending.pop();\n\n if (path === undefined) {\n break;\n }\n\n if (dependencies.has(path)) {\n continue;\n }\n\n dependencies.add(path);\n pending.push(...directDependencies(path, configName, configRoot));\n }\n\n return [...dependencies];\n};\n\nexport { resolveConfigDependencies };\n"]}
|