auklet 0.0.16 → 0.0.18
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 +37 -1
- package/dist/build/bundleConfig.d.ts +1 -4
- package/dist/build/bundleConfig.js +59 -71
- package/dist/build/cleanOutput.d.ts +2 -8
- package/dist/build/cleanOutput.js +7 -7
- package/dist/build/moduleConfig.d.ts +1 -3
- package/dist/build/moduleConfig.js +21 -40
- package/dist/build/runTsdown.d.ts +2 -5
- package/dist/build/runTsdown.js +18 -23
- package/dist/build/tsdown/common.d.ts +17 -28
- package/dist/build/tsdown/common.js +22 -25
- package/dist/build/tsdown/context.d.ts +16 -20
- package/dist/build/tsdown/context.js +41 -45
- package/dist/build/tsdown/define.d.ts +2 -7
- package/dist/build/tsdown/define.js +13 -22
- package/dist/build/tsdown/dependencies.d.ts +4 -12
- package/dist/build/tsdown/dependencies.js +47 -51
- package/dist/build/tsdown/entries.d.ts +4 -6
- package/dist/build/tsdown/entries.js +39 -38
- package/dist/build/tsdown/parseModuleId.d.ts +4 -4
- package/dist/build/tsdown/parseModuleId.js +92 -77
- package/dist/build/tsdown/types.d.ts +24 -31
- package/dist/build/tsdownConfig.js +1 -4
- package/dist/config.d.ts +37 -37
- package/dist/config.js +38 -41
- package/dist/configLoader.d.ts +2 -7
- package/dist/configLoader.js +59 -64
- package/dist/css/config.js +8 -8
- package/dist/css/constants.d.ts +7 -7
- package/dist/css/constants.js +1 -1
- package/dist/css/core/resolvers/packageImports.d.ts +1 -5
- package/dist/css/core/resolvers/packageImports.js +35 -40
- package/dist/css/core/resolvers/relative.d.ts +1 -4
- package/dist/css/core/resolvers/relative.js +3 -2
- package/dist/css/core/resolvers/tsconfigPaths.d.ts +1 -5
- package/dist/css/core/resolvers/tsconfigPaths.js +59 -66
- package/dist/css/core/style/dependencies.d.ts +6 -16
- package/dist/css/core/style/dependencies.js +35 -38
- package/dist/css/core/style/entries.d.ts +35 -58
- package/dist/css/core/style/entries.js +22 -33
- package/dist/css/core/style/files.d.ts +2 -7
- package/dist/css/core/style/files.js +11 -11
- package/dist/css/core/style/specifier.d.ts +41 -8
- package/dist/css/core/style/specifier.js +107 -18
- package/dist/css/core/styleImports/autoImportRules.d.ts +13 -0
- package/dist/css/core/styleImports/autoImportRules.js +68 -0
- package/dist/css/core/styleImports/collector.d.ts +12 -25
- package/dist/css/core/styleImports/collector.js +101 -206
- package/dist/css/core/styleImports/sourceImportExportAnalyzer.d.ts +11 -0
- package/dist/css/core/styleImports/sourceImportExportAnalyzer.js +173 -0
- package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
- package/dist/css/core/styleModuleEntryPlanner.js +45 -62
- package/dist/css/core/stylePackageContext.d.ts +16 -20
- package/dist/css/core/stylePackageContext.js +33 -49
- package/dist/css/core/styleProcessor.js +105 -104
- package/dist/css/core/workspaceStyleResolver.d.ts +8 -15
- package/dist/css/core/workspaceStyleResolver.js +34 -76
- package/dist/css/production/builder.d.ts +9 -16
- package/dist/css/production/builder.js +51 -57
- package/dist/css/production/format/entryWriter.js +36 -49
- package/dist/css/production/format/externalWriter.js +21 -33
- package/dist/css/production/format/{componentWriter.d.ts → moduleEntryWriter.d.ts} +1 -1
- package/dist/css/production/format/moduleEntryWriter.js +48 -0
- package/dist/css/production/format/moduleWriter.js +23 -26
- package/dist/css/production/format/shared.d.ts +8 -15
- package/dist/css/production/format/shared.js +4 -9
- package/dist/css/production/format/sourceWriter.js +11 -11
- package/dist/css/production/format/themeWriter.js +56 -71
- package/dist/css/production/moduleOutputWriter.d.ts +18 -21
- package/dist/css/production/moduleOutputWriter.js +58 -67
- package/dist/css/production/packageEntryWriter.d.ts +12 -15
- package/dist/css/production/packageEntryWriter.js +42 -45
- package/dist/css/vite/hmr.d.ts +11 -11
- package/dist/css/vite/hmr.js +93 -109
- package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
- package/dist/css/vite/moduleGraph/devDependency.js +8 -8
- package/dist/css/vite/moduleGraph/graph.d.ts +20 -23
- package/dist/css/vite/moduleGraph/graph.js +51 -50
- package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
- package/dist/css/vite/moduleGraph/loadResult.js +7 -9
- package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +16 -7
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +60 -68
- package/dist/css/vite/moduleGraph/packageSource/singlePackage.d.ts +21 -0
- package/dist/css/vite/moduleGraph/packageSource/singlePackage.js +63 -0
- package/dist/css/vite/moduleGraph/packageSource/types.d.ts +7 -7
- package/dist/css/vite/moduleGraph/requestCache.d.ts +46 -57
- package/dist/css/vite/moduleGraph/requestCache.js +53 -51
- package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
- package/dist/css/vite/moduleGraph/styleCodeFactory.js +173 -264
- package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
- package/dist/css/vite/moduleGraph/styleId.js +12 -11
- package/dist/css/vite/moduleGraph/types.d.ts +11 -14
- package/dist/css/vite/vitePlugin.d.ts +16 -20
- package/dist/css/vite/vitePlugin.js +117 -109
- package/dist/css/watch/watcher.d.ts +15 -21
- package/dist/css/watch/watcher.js +84 -81
- package/dist/index.d.ts +3 -25
- package/dist/index.js +2 -9
- package/dist/types.d.ts +59 -62
- package/dist/utils.d.ts +3 -7
- package/dist/utils.js +50 -47
- package/package.json +31 -33
- package/dist/css/core/styleImports/sourceReference.d.ts +0 -19
- package/dist/css/core/styleImports/sourceReference.js +0 -193
- package/dist/css/production/format/componentWriter.js +0 -71
package/dist/config.js
CHANGED
|
@@ -1,50 +1,47 @@
|
|
|
1
1
|
export const aukletConfigFile = 'auklet.config.ts';
|
|
2
2
|
export const aukletDefaultOptions = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
source: 'src',
|
|
4
|
+
output: 'dist',
|
|
5
|
+
modules: false,
|
|
6
|
+
build: {
|
|
7
|
+
formats: ['cjs', 'esm', 'iife'],
|
|
8
|
+
target: 'es2020',
|
|
9
|
+
platform: 'neutral',
|
|
10
|
+
},
|
|
11
|
+
styles: {
|
|
12
|
+
themes: {},
|
|
13
|
+
dependencies: {},
|
|
14
|
+
},
|
|
15
15
|
};
|
|
16
16
|
export const aukletDefaultStyleDependencyConfig = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
entry: '/style.css',
|
|
18
|
+
components: ['/pages/**.css', '/components/**.css'],
|
|
19
|
+
themes: {
|
|
20
|
+
dark: '/themes/dark.css',
|
|
21
|
+
light: '/themes/light.css',
|
|
22
|
+
},
|
|
23
23
|
};
|
|
24
24
|
const normalizeStyleDependency = (dependency) => ({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
entry: dependency.entry,
|
|
26
|
+
themes: dependency.themes,
|
|
27
|
+
components: dependency.components,
|
|
28
28
|
});
|
|
29
29
|
export function normalizeAukletConfig(config = {}) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
),
|
|
48
|
-
},
|
|
49
|
-
};
|
|
30
|
+
const dependencies = config.styles?.dependencies ?? aukletDefaultOptions.styles.dependencies;
|
|
31
|
+
return {
|
|
32
|
+
source: config.source ?? aukletDefaultOptions.source,
|
|
33
|
+
output: config.output ?? aukletDefaultOptions.output,
|
|
34
|
+
modules: config.modules ?? aukletDefaultOptions.modules,
|
|
35
|
+
build: {
|
|
36
|
+
...aukletDefaultOptions.build,
|
|
37
|
+
...config.build,
|
|
38
|
+
},
|
|
39
|
+
styles: {
|
|
40
|
+
themes: config.styles?.themes ?? aukletDefaultOptions.styles.themes,
|
|
41
|
+
dependencies: Object.fromEntries(Object.entries(dependencies).map(([packageName, dependency]) => [
|
|
42
|
+
packageName,
|
|
43
|
+
normalizeStyleDependency(dependency),
|
|
44
|
+
])),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
50
47
|
}
|
package/dist/configLoader.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import type { AukletConfig, LoadAukletConfigOptions } from '#auklet/types';
|
|
2
|
-
export declare function resolveAukletConfigModule(
|
|
3
|
-
|
|
4
|
-
): AukletConfig;
|
|
5
|
-
export declare function loadAukletConfig(
|
|
6
|
-
packageRoot: string,
|
|
7
|
-
options?: LoadAukletConfigOptions,
|
|
8
|
-
): Promise<AukletConfig>;
|
|
2
|
+
export declare function resolveAukletConfigModule(module: Record<string, unknown>): AukletConfig;
|
|
3
|
+
export declare function loadAukletConfig(packageRoot: string, options?: LoadAukletConfigOptions): Promise<AukletConfig>;
|
package/dist/configLoader.js
CHANGED
|
@@ -4,81 +4,76 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
4
4
|
import ts from 'typescript';
|
|
5
5
|
import { aukletConfigFile } from '#auklet/config';
|
|
6
6
|
const importAukletConfigModule = async (configPath, href) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
try {
|
|
8
|
+
return (await import(href));
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (!isUnknownTsExtensionError(error) || !configPath.endsWith('.ts')) {
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
return importTsOptionsModule(href);
|
|
12
15
|
}
|
|
13
|
-
return importTsOptionsModule(href);
|
|
14
|
-
}
|
|
15
16
|
};
|
|
16
17
|
const importTsOptionsModule = async (href) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
fs.rmSync(tempFile, { force: true });
|
|
36
|
-
}
|
|
18
|
+
const configPath = fileURLToPath(href);
|
|
19
|
+
const source = fs.readFileSync(configPath, 'utf8');
|
|
20
|
+
const output = ts.transpileModule(source, {
|
|
21
|
+
compilerOptions: {
|
|
22
|
+
esModuleInterop: true,
|
|
23
|
+
module: ts.ModuleKind.ESNext,
|
|
24
|
+
target: ts.ScriptTarget.ES2020,
|
|
25
|
+
},
|
|
26
|
+
fileName: configPath,
|
|
27
|
+
});
|
|
28
|
+
const tempFile = path.join(path.dirname(configPath), `.auklet.config.${process.pid}.${Date.now()}.mjs`);
|
|
29
|
+
fs.writeFileSync(tempFile, output.outputText);
|
|
30
|
+
try {
|
|
31
|
+
return (await import(pathToFileURL(tempFile).href));
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
fs.rmSync(tempFile, { force: true });
|
|
35
|
+
}
|
|
37
36
|
};
|
|
38
37
|
const isUnknownTsExtensionError = (error) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
error.code === 'ERR_UNKNOWN_FILE_EXTENSION'
|
|
43
|
-
);
|
|
38
|
+
return (error instanceof TypeError &&
|
|
39
|
+
'code' in error &&
|
|
40
|
+
error.code === 'ERR_UNKNOWN_FILE_EXTENSION');
|
|
44
41
|
};
|
|
45
42
|
const asRecord = (value) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
50
47
|
};
|
|
51
48
|
export function resolveAukletConfigModule(module) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
const candidates = [
|
|
50
|
+
module,
|
|
51
|
+
asRecord(module.default),
|
|
52
|
+
asRecord(module['module.exports']),
|
|
53
|
+
];
|
|
54
|
+
for (const candidate of candidates) {
|
|
55
|
+
if (!candidate)
|
|
56
|
+
continue;
|
|
57
|
+
const config = asRecord(candidate.config);
|
|
58
|
+
if (config) {
|
|
59
|
+
return config;
|
|
60
|
+
}
|
|
62
61
|
}
|
|
63
|
-
|
|
64
|
-
return {};
|
|
62
|
+
return {};
|
|
65
63
|
}
|
|
66
64
|
export async function loadAukletConfig(packageRoot, options = {}) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const module = await
|
|
65
|
+
const configPath = path.join(packageRoot, options.configFile ?? aukletConfigFile);
|
|
66
|
+
if (!fs.existsSync(configPath)) {
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
const url = pathToFileURL(configPath);
|
|
70
|
+
if (options.cacheBust) {
|
|
71
|
+
url.searchParams.set('t', Date.now().toString());
|
|
72
|
+
}
|
|
73
|
+
if (configPath.endsWith('.ts')) {
|
|
74
|
+
const module = await importTsOptionsModule(url.href);
|
|
75
|
+
return resolveAukletConfigModule(module);
|
|
76
|
+
}
|
|
77
|
+
const module = await importAukletConfigModule(configPath, url.href);
|
|
80
78
|
return resolveAukletConfigModule(module);
|
|
81
|
-
}
|
|
82
|
-
const module = await importAukletConfigModule(configPath, url.href);
|
|
83
|
-
return resolveAukletConfigModule(module);
|
|
84
79
|
}
|
package/dist/css/config.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export const moduleStyleBuildConfig = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
styleExtensions: ['.css'],
|
|
3
|
+
output: {
|
|
4
|
+
styleDir: 'style',
|
|
5
|
+
indexStyleFile: 'index.css',
|
|
6
|
+
moduleStyleFile: 'module.css',
|
|
7
|
+
externalStyleFile: 'external.css',
|
|
8
|
+
outputFormats: ['es', 'lib'],
|
|
9
|
+
},
|
|
10
10
|
};
|
package/dist/css/constants.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare const NODE_MODULES_DIR =
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const THEMES_DIR =
|
|
4
|
-
export declare const THEMES_ENTRY_PREFIX =
|
|
5
|
-
export declare const STYLE_ENTRY =
|
|
6
|
-
export declare const MODULE_ENTRY =
|
|
7
|
-
export declare const EXTERNAL_ENTRY =
|
|
1
|
+
export declare const NODE_MODULES_DIR = "node_modules";
|
|
2
|
+
export declare const SOURCE_MODULE_RE: RegExp;
|
|
3
|
+
export declare const THEMES_DIR = "themes";
|
|
4
|
+
export declare const THEMES_ENTRY_PREFIX = "themes/";
|
|
5
|
+
export declare const STYLE_ENTRY = "style.css";
|
|
6
|
+
export declare const MODULE_ENTRY = "module.css";
|
|
7
|
+
export declare const EXTERNAL_ENTRY = "external.css";
|
package/dist/css/constants.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const NODE_MODULES_DIR = 'node_modules';
|
|
2
|
-
export const
|
|
2
|
+
export const SOURCE_MODULE_RE = /\.tsx$/;
|
|
3
3
|
export const THEMES_DIR = 'themes';
|
|
4
4
|
export const THEMES_ENTRY_PREFIX = 'themes/';
|
|
5
5
|
export const STYLE_ENTRY = 'style.css';
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export declare function resolvePackageImportsSourceImport(
|
|
2
|
-
packageRoot: string,
|
|
3
|
-
sourceRoot: string,
|
|
4
|
-
importPath: string,
|
|
5
|
-
): string[];
|
|
1
|
+
export declare function resolvePackageImportsSourceImport(packageRoot: string, sourceRoot: string, importPath: string): string[];
|
|
@@ -5,49 +5,44 @@ import { POSIX_SEPARATOR, toPosixPath } from '#auklet/utils';
|
|
|
5
5
|
const conditions = ['source', 'import', 'default'];
|
|
6
6
|
const sourceExtensions = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
7
7
|
const readPackageImports = (packageRoot) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
const packageJsonPath = path.join(packageRoot, 'package.json');
|
|
9
|
+
if (!fs.existsSync(packageJsonPath))
|
|
10
|
+
return {};
|
|
11
|
+
try {
|
|
12
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
13
|
+
return packageJson.imports ?? {};
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
16
18
|
};
|
|
17
19
|
const trimSourceExtension = (value) => {
|
|
18
|
-
|
|
20
|
+
return value.replace(sourceExtensions, '');
|
|
19
21
|
};
|
|
20
22
|
const toSourceRelativePath = (packageRoot, sourceRoot, target) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (!target.startsWith('.'))
|
|
24
|
+
return null;
|
|
25
|
+
const file = path.resolve(packageRoot, target);
|
|
26
|
+
const relative = path.relative(sourceRoot, file);
|
|
27
|
+
if (relative.startsWith('..') || path.isAbsolute(relative))
|
|
28
|
+
return null;
|
|
29
|
+
return trimSourceExtension(toPosixPath(relative));
|
|
26
30
|
};
|
|
27
|
-
export function resolvePackageImportsSourceImport(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!resolved) return [];
|
|
45
|
-
const sourceRelativePath = toSourceRelativePath(
|
|
46
|
-
packageRoot,
|
|
47
|
-
sourceRoot,
|
|
48
|
-
resolved,
|
|
49
|
-
);
|
|
50
|
-
return sourceRelativePath
|
|
51
|
-
? [sourceRelativePath.split(POSIX_SEPARATOR).join(path.sep)]
|
|
52
|
-
: [];
|
|
31
|
+
export function resolvePackageImportsSourceImport(packageRoot, sourceRoot, importPath) {
|
|
32
|
+
if (!importPath.startsWith('#'))
|
|
33
|
+
return [];
|
|
34
|
+
const resolved = (() => {
|
|
35
|
+
try {
|
|
36
|
+
return findPathInImports(importPath, readPackageImports(packageRoot), conditions);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
42
|
+
if (!resolved)
|
|
43
|
+
return [];
|
|
44
|
+
const sourceRelativePath = toSourceRelativePath(packageRoot, sourceRoot, resolved);
|
|
45
|
+
return sourceRelativePath
|
|
46
|
+
? [sourceRelativePath.split(POSIX_SEPARATOR).join(path.sep)]
|
|
47
|
+
: [];
|
|
53
48
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
export function resolveRelativeSourceImport(sourceDir, importPath) {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
if (!importPath.startsWith('.'))
|
|
4
|
+
return [];
|
|
5
|
+
return [path.normalize(path.join(sourceDir, importPath))];
|
|
5
6
|
}
|
|
@@ -4,82 +4,75 @@ import ts from 'typescript';
|
|
|
4
4
|
import { POSIX_SEPARATOR, toPosixPath } from '#auklet/utils';
|
|
5
5
|
const sourceExtensions = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
6
6
|
const findTsconfig = (packageRoot) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
let current = packageRoot;
|
|
8
|
+
while (true) {
|
|
9
|
+
const tsconfig = path.join(current, 'tsconfig.json');
|
|
10
|
+
if (fs.existsSync(tsconfig))
|
|
11
|
+
return tsconfig;
|
|
12
|
+
const parent = path.dirname(current);
|
|
13
|
+
if (parent === current)
|
|
14
|
+
return null;
|
|
15
|
+
current = parent;
|
|
16
|
+
}
|
|
15
17
|
};
|
|
16
18
|
const readTsconfigPaths = (packageRoot) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
ts.sys,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
baseUrl: parsed.options.baseUrl ?? path.dirname(tsconfig),
|
|
30
|
-
paths: parsed.options.paths ?? {},
|
|
31
|
-
};
|
|
19
|
+
const tsconfig = findTsconfig(packageRoot);
|
|
20
|
+
if (!tsconfig)
|
|
21
|
+
return null;
|
|
22
|
+
const loaded = ts.readConfigFile(tsconfig, ts.sys.readFile);
|
|
23
|
+
if (loaded.error)
|
|
24
|
+
return null;
|
|
25
|
+
const parsed = ts.parseJsonConfigFileContent(loaded.config, ts.sys, path.dirname(tsconfig), {}, tsconfig);
|
|
26
|
+
return {
|
|
27
|
+
baseUrl: parsed.options.baseUrl ?? path.dirname(tsconfig),
|
|
28
|
+
paths: parsed.options.paths ?? {},
|
|
29
|
+
};
|
|
32
30
|
};
|
|
33
31
|
const resolvePattern = (pattern, target, importPath) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
prefix.length,
|
|
43
|
-
|
|
44
|
-
);
|
|
45
|
-
return target.replace(/\*/g, value);
|
|
32
|
+
const wildcardIndex = pattern.indexOf('*');
|
|
33
|
+
if (wildcardIndex < 0)
|
|
34
|
+
return pattern === importPath ? target : null;
|
|
35
|
+
const prefix = pattern.slice(0, wildcardIndex);
|
|
36
|
+
const suffix = pattern.slice(wildcardIndex + 1);
|
|
37
|
+
if (!importPath.startsWith(prefix) || !importPath.endsWith(suffix)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const value = importPath.slice(prefix.length, importPath.length - suffix.length);
|
|
41
|
+
return target.replace(/\*/g, value);
|
|
46
42
|
};
|
|
47
43
|
const getPatternScore = (pattern) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
const wildcardIndex = pattern.indexOf('*');
|
|
45
|
+
if (wildcardIndex < 0)
|
|
46
|
+
return Number.MAX_SAFE_INTEGER;
|
|
47
|
+
return pattern.slice(0, wildcardIndex).length;
|
|
51
48
|
};
|
|
52
49
|
const trimSourceExtension = (value) => {
|
|
53
|
-
|
|
50
|
+
return value.replace(sourceExtensions, '');
|
|
54
51
|
};
|
|
55
52
|
const toSourceRelativePath = (sourceRoot, file) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
const relative = path.relative(sourceRoot, file);
|
|
54
|
+
if (relative.startsWith('..') || path.isAbsolute(relative))
|
|
55
|
+
return null;
|
|
56
|
+
return trimSourceExtension(toPosixPath(relative));
|
|
59
57
|
};
|
|
60
|
-
export function resolveTsconfigPathsSourceImport(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
path: sourceRelativePath.split(POSIX_SEPARATOR).join(path.sep),
|
|
79
|
-
score: getPatternScore(pattern),
|
|
80
|
-
});
|
|
81
|
-
}
|
|
58
|
+
export function resolveTsconfigPathsSourceImport(packageRoot, sourceRoot, importPath) {
|
|
59
|
+
const config = readTsconfigPaths(packageRoot);
|
|
60
|
+
if (!config)
|
|
61
|
+
return [];
|
|
62
|
+
const matches = [];
|
|
63
|
+
for (const [pattern, targets] of Object.entries(config.paths)) {
|
|
64
|
+
for (const target of targets) {
|
|
65
|
+
const resolved = resolvePattern(pattern, target, importPath);
|
|
66
|
+
if (!resolved)
|
|
67
|
+
continue;
|
|
68
|
+
const sourceRelativePath = toSourceRelativePath(sourceRoot, path.resolve(config.baseUrl, resolved));
|
|
69
|
+
if (sourceRelativePath) {
|
|
70
|
+
matches.push({
|
|
71
|
+
path: sourceRelativePath.split(POSIX_SEPARATOR).join(path.sep),
|
|
72
|
+
score: getPatternScore(pattern),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
82
76
|
}
|
|
83
|
-
|
|
84
|
-
return matches.sort((a, b) => b.score - a.score).map((match) => match.path);
|
|
77
|
+
return matches.sort((a, b) => b.score - a.score).map((match) => match.path);
|
|
85
78
|
}
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import type { NormalizedAukletConfig } from '#auklet/types';
|
|
2
|
-
export declare function getGlobalStyleDependencies(
|
|
3
|
-
|
|
4
|
-
): string[];
|
|
5
|
-
export declare function getExternalStyleDependencies(
|
|
6
|
-
config: NormalizedAukletConfig,
|
|
7
|
-
): string[];
|
|
8
|
-
export declare function getThemeStyleDependencies(
|
|
9
|
-
config: NormalizedAukletConfig,
|
|
10
|
-
themeName: string,
|
|
11
|
-
): string[];
|
|
2
|
+
export declare function getGlobalStyleDependencies(config: NormalizedAukletConfig): string[];
|
|
3
|
+
export declare function getExternalStyleDependencies(config: NormalizedAukletConfig): string[];
|
|
4
|
+
export declare function getThemeStyleDependencies(config: NormalizedAukletConfig, themeName: string): string[];
|
|
12
5
|
export declare function getThemeNames(config: NormalizedAukletConfig): string[];
|
|
13
6
|
export declare function getThemeStyleEntries(config: NormalizedAukletConfig): {
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
themeName: string;
|
|
8
|
+
file: string;
|
|
16
9
|
}[];
|
|
17
|
-
export declare function resolveThemeStyleFiles(
|
|
18
|
-
config: NormalizedAukletConfig,
|
|
19
|
-
packageRoot: string,
|
|
20
|
-
): Map<string, string>;
|
|
10
|
+
export declare function resolveThemeStyleFiles(config: NormalizedAukletConfig, packageRoot: string): Map<string, string>;
|