@wyw-in-js/shared 1.1.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/IVariableContext.js +1 -1
- package/esm/IVariableContext.js.map +1 -1
- package/esm/asyncResolveFallback.js +35 -31
- package/esm/asyncResolveFallback.js.map +1 -1
- package/esm/asyncResolverFactory.js +9 -9
- package/esm/asyncResolverFactory.js.map +1 -1
- package/esm/debugger.js +1 -1
- package/esm/debugger.js.map +1 -1
- package/esm/findPackageJSON.js +60 -68
- package/esm/findPackageJSON.js.map +1 -1
- package/esm/hasEvalMeta.js +2 -2
- package/esm/hasEvalMeta.js.map +1 -1
- package/esm/index.js +11 -10
- package/esm/index.js.map +1 -1
- package/esm/isBoxedPrimitive.js +4 -5
- package/esm/isBoxedPrimitive.js.map +1 -1
- package/esm/logger.js +17 -17
- package/esm/logger.js.map +1 -1
- package/esm/options/isFeatureEnabled.js +22 -27
- package/esm/options/isFeatureEnabled.js.map +1 -1
- package/esm/options/nativeResolverOptions.js +49 -0
- package/esm/options/nativeResolverOptions.js.map +1 -0
- package/esm/options/types.js +1 -1
- package/esm/options/types.js.map +1 -1
- package/esm/slugify.js +47 -49
- package/esm/slugify.js.map +1 -1
- package/esm/types.js +6 -10
- package/esm/types.js.map +1 -1
- package/package.json +12 -10
- package/types/IVariableContext.js +1 -2
- package/types/asyncResolveFallback.js +8 -14
- package/types/asyncResolverFactory.js +1 -5
- package/types/debugger.js +1 -2
- package/types/findPackageJSON.js +13 -17
- package/types/hasEvalMeta.js +1 -4
- package/types/index.d.ts +4 -2
- package/types/index.js +10 -23
- package/types/isBoxedPrimitive.js +1 -4
- package/types/logger.js +7 -14
- package/types/options/isFeatureEnabled.js +3 -7
- package/types/options/nativeResolverOptions.d.ts +4 -0
- package/types/options/nativeResolverOptions.js +55 -0
- package/types/options/types.d.ts +120 -10
- package/types/options/types.js +1 -2
- package/types/slugify.js +1 -4
- package/types/types.d.ts +40 -1
- package/types/types.js +2 -5
- package/esm/babel.js +0 -2
- package/esm/babel.js.map +0 -1
- package/lib/IVariableContext.js +0 -2
- package/lib/IVariableContext.js.map +0 -1
- package/lib/asyncResolveFallback.js +0 -47
- package/lib/asyncResolveFallback.js.map +0 -1
- package/lib/asyncResolverFactory.js +0 -18
- package/lib/asyncResolverFactory.js.map +0 -1
- package/lib/babel.js +0 -2
- package/lib/babel.js.map +0 -1
- package/lib/debugger.js +0 -2
- package/lib/debugger.js.map +0 -1
- package/lib/findPackageJSON.js +0 -81
- package/lib/findPackageJSON.js.map +0 -1
- package/lib/hasEvalMeta.js +0 -10
- package/lib/hasEvalMeta.js.map +0 -1
- package/lib/index.js +0 -81
- package/lib/index.js.map +0 -1
- package/lib/isBoxedPrimitive.js +0 -15
- package/lib/isBoxedPrimitive.js.map +0 -1
- package/lib/logger.js +0 -35
- package/lib/logger.js.map +0 -1
- package/lib/options/isFeatureEnabled.js +0 -37
- package/lib/options/isFeatureEnabled.js.map +0 -1
- package/lib/options/types.js +0 -2
- package/lib/options/types.js.map +0 -1
- package/lib/slugify.js +0 -68
- package/lib/slugify.js.map +0 -1
- package/lib/types.js +0 -16
- package/lib/types.js.map +0 -1
- package/types/babel.d.ts +0 -2
- package/types/babel.js +0 -2
package/esm/IVariableContext.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=IVariableContext.js.map
|
|
2
|
+
//# sourceMappingURL=IVariableContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"","names":[],"sources":["../src/IVariableContext.ts"],"version":3,"sourcesContent":["export interface IVariableContext {\n componentName: string;\n componentSlug: string;\n index: number;\n precedingCss: string;\n processor: string;\n source: string;\n unit: string;\n valueSlug: string;\n}\n"],"file":"IVariableContext.js"}
|
|
@@ -1,38 +1,42 @@
|
|
|
1
|
-
import path from
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
2
4
|
const safeResolve = (name, where) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return e;
|
|
9
|
-
}
|
|
5
|
+
try {
|
|
6
|
+
return nodeRequire.resolve(name, { paths: where });
|
|
7
|
+
} catch (e) {
|
|
8
|
+
return e;
|
|
9
|
+
}
|
|
10
10
|
};
|
|
11
|
-
const suffixes = [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const suffixes = [
|
|
12
|
+
".js",
|
|
13
|
+
".ts",
|
|
14
|
+
".jsx",
|
|
15
|
+
".tsx"
|
|
16
|
+
].reduce((acc, ext) => {
|
|
17
|
+
acc.push(`/index${ext}`);
|
|
18
|
+
acc.push(ext);
|
|
19
|
+
return acc;
|
|
15
20
|
}, []);
|
|
16
21
|
export const syncResolve = (what, importer, stack) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
throw resolved;
|
|
22
|
+
const where = [importer, ...stack].map((p) => path.dirname(p));
|
|
23
|
+
const resolved = safeResolve(what, where);
|
|
24
|
+
if (!(resolved instanceof Error)) {
|
|
25
|
+
return resolved;
|
|
26
|
+
}
|
|
27
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
28
|
+
for (const suffix of suffixes) {
|
|
29
|
+
const resolvedWithSuffix = safeResolve(what + suffix, where);
|
|
30
|
+
if (resolvedWithSuffix instanceof Error) {
|
|
31
|
+
// eslint-disable-next-line no-continue
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
return resolvedWithSuffix;
|
|
35
|
+
}
|
|
36
|
+
throw resolved;
|
|
33
37
|
};
|
|
34
38
|
export const asyncResolveFallback = (what, importer, stack) => {
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
const resolved = syncResolve(what, importer, stack);
|
|
40
|
+
return Promise.resolve(resolved);
|
|
37
41
|
};
|
|
38
|
-
//# sourceMappingURL=asyncResolveFallback.js.map
|
|
42
|
+
//# sourceMappingURL=asyncResolveFallback.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,MAAM,cAAc,cAAc,OAAO,KAAK,IAAI;AAElD,MAAM,eAAe,MAAc,UAAoC;AACrE,KAAI;AACF,SAAO,YAAY,QAAQ,MAAM,EAC/B,OAAO,OACR,CAAC;UACK,GAAY;AACnB,SAAO;;;AAIX,MAAM,WAAW;CAAC;CAAO;CAAO;CAAQ;CAAO,CAAC,QAAQ,KAAe,QAAQ;AAC7E,KAAI,KAAK,SAAS,MAAM;AACxB,KAAI,KAAK,IAAI;AACb,QAAO;GACN,EAAE,CAAC;AAEN,OAAO,MAAM,eACX,MACA,UACA,UACW;CACX,MAAM,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,KAAK,MAAM,KAAK,QAAQ,EAAE,CAAC;CAC9D,MAAM,WAAW,YAAY,MAAM,MAAM;AACzC,KAAI,EAAE,oBAAoB,QAAQ;AAChC,SAAO;;;AAIT,MAAK,MAAM,UAAU,UAAU;EAC7B,MAAM,qBAAqB,YAAY,OAAO,QAAQ,MAAM;AAC5D,MAAI,8BAA8B,OAAO;;AAEvC;;AAGF,SAAO;;AAGT,OAAM;;AAGR,OAAO,MAAM,wBACX,MACA,UACA,UACoB;CACpB,MAAM,WAAW,YAAY,MAAM,UAAU,MAAM;AACnD,QAAO,QAAQ,QAAQ,SAAS","names":[],"sources":["../src/asyncResolveFallback.ts"],"version":3,"sourcesContent":["import path from 'path';\nimport { createRequire } from 'module';\n\nconst nodeRequire = createRequire(import.meta.url);\n\nconst safeResolve = (name: string, where: string[]): string | Error => {\n try {\n return nodeRequire.resolve(name, {\n paths: where,\n });\n } catch (e: unknown) {\n return e as Error;\n }\n};\n\nconst suffixes = ['.js', '.ts', '.jsx', '.tsx'].reduce((acc: string[], ext) => {\n acc.push(`/index${ext}`);\n acc.push(ext);\n return acc;\n}, []);\n\nexport const syncResolve = (\n what: string,\n importer: string,\n stack: string[]\n): string => {\n const where = [importer, ...stack].map((p) => path.dirname(p));\n const resolved = safeResolve(what, where);\n if (!(resolved instanceof Error)) {\n return resolved;\n }\n\n // eslint-disable-next-line no-restricted-syntax\n for (const suffix of suffixes) {\n const resolvedWithSuffix = safeResolve(what + suffix, where);\n if (resolvedWithSuffix instanceof Error) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n return resolvedWithSuffix;\n }\n\n throw resolved;\n};\n\nexport const asyncResolveFallback = (\n what: string,\n importer: string,\n stack: string[]\n): Promise<string> => {\n const resolved = syncResolve(what, importer, stack);\n return Promise.resolve(resolved);\n};\n"],"file":"asyncResolveFallback.js"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export const asyncResolverFactory = (onResolve, mapper) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
const memoizedSyncResolve = new WeakMap();
|
|
3
|
+
return (resolveFn) => {
|
|
4
|
+
if (!memoizedSyncResolve.has(resolveFn)) {
|
|
5
|
+
const fn = (what, importer, stack) => resolveFn(...mapper(what, importer, stack)).then((resolved) => onResolve(resolved, what, importer, stack));
|
|
6
|
+
memoizedSyncResolve.set(resolveFn, fn);
|
|
7
|
+
}
|
|
8
|
+
return memoizedSyncResolve.get(resolveFn);
|
|
9
|
+
};
|
|
10
10
|
};
|
|
11
|
-
//# sourceMappingURL=asyncResolverFactory.js.map
|
|
11
|
+
//# sourceMappingURL=asyncResolverFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,OAAO,MAAM,wBAKX,WAMA,WACG;CACH,MAAM,sBAAsB,IAAI,SAG7B;AAEH,SAAQ,cAAwB;AAC9B,MAAI,CAAC,oBAAoB,IAAI,UAAU,EAAE;GACvC,MAAM,MACJ,MACA,UACA,UAEA,UAAU,GAAG,OAAO,MAAM,UAAU,MAAM,CAAC,CAAC,MAAM,aAChD,UAAU,UAAU,MAAM,UAAU,MAAM,CAC3C;AAEH,uBAAoB,IAAI,WAAW,GAAG;;AAGxC,SAAO,oBAAoB,IAAI,UAAU","names":[],"sources":["../src/asyncResolverFactory.ts"],"version":3,"sourcesContent":["export const asyncResolverFactory = <\n TResolved,\n const TResolverArgs extends readonly unknown[],\n TResolve extends (...args: TResolverArgs) => Promise<TResolved>,\n>(\n onResolve: (\n resolved: TResolved,\n what: string,\n importer: string,\n stack: string[]\n ) => Promise<string | null>,\n mapper: (what: string, importer: string, stack: string[]) => TResolverArgs\n) => {\n const memoizedSyncResolve = new WeakMap<\n TResolve,\n (what: string, importer: string, stack: string[]) => Promise<string | null>\n >();\n\n return (resolveFn: TResolve) => {\n if (!memoizedSyncResolve.has(resolveFn)) {\n const fn = (\n what: string,\n importer: string,\n stack: string[]\n ): Promise<string | null> =>\n resolveFn(...mapper(what, importer, stack)).then((resolved) =>\n onResolve(resolved, what, importer, stack)\n );\n\n memoizedSyncResolve.set(resolveFn, fn);\n }\n\n return memoizedSyncResolve.get(resolveFn)!;\n };\n};\n"],"file":"asyncResolverFactory.js"}
|
package/esm/debugger.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=debugger.js.map
|
|
2
|
+
//# sourceMappingURL=debugger.js.map
|
package/esm/debugger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"","names":[],"sources":["../src/debugger.ts"],"version":3,"sourcesContent":["export type Debugger = {\n (formatter: unknown, ...args: unknown[]): void;\n color: string;\n destroy: () => boolean;\n diff: number;\n enabled: boolean;\n extend: (namespace: string, delimiter?: string) => Debugger;\n log: (...args: unknown[]) => unknown;\n namespace: string;\n};\n"],"file":"debugger.js"}
|
package/esm/findPackageJSON.js
CHANGED
|
@@ -1,73 +1,65 @@
|
|
|
1
|
-
import { readFileSync } from
|
|
2
|
-
import { dirname, isAbsolute } from
|
|
3
|
-
import
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { dirname, isAbsolute } from "path";
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
import findUp from "find-up";
|
|
4
5
|
const cache = new Map();
|
|
6
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
5
7
|
function findSelfPackageJSON(pkgName, filename) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
8
|
+
const packageJSONPath = findUp.sync("package.json", { cwd: dirname(filename) });
|
|
9
|
+
if (!packageJSONPath) return undefined;
|
|
10
|
+
try {
|
|
11
|
+
const packageJSON = JSON.parse(readFileSync(packageJSONPath, "utf8"));
|
|
12
|
+
return packageJSON?.name === pkgName ? packageJSONPath : undefined;
|
|
13
|
+
} catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
export function findPackageJSON(pkgName, filename) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// package here, but it does not solve all cases because `pkgName`
|
|
65
|
-
// can be an alias and should be resolved by a bundler. However, we can't use
|
|
66
|
-
// `resolve` from a bundler because it is async. The good news is that in that
|
|
67
|
-
// specific case, we can just ignore those packages. For now.
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
throw er;
|
|
71
|
-
}
|
|
18
|
+
// Jest's resolver does not work properly with `moduleNameMapper` when `paths` are defined
|
|
19
|
+
const isJest = Boolean(globalThis.process?.env?.JEST_WORKER_ID);
|
|
20
|
+
const skipPathsOptions = isJest && !pkgName.startsWith(".");
|
|
21
|
+
try {
|
|
22
|
+
const pkgPath = pkgName === "." && filename && isAbsolute(filename) ? filename : nodeRequire.resolve(pkgName, filename ? { paths: [dirname(filename)] } : {});
|
|
23
|
+
if (!cache.has(pkgPath)) {
|
|
24
|
+
cache.set(pkgPath, findUp.sync("package.json", { cwd: pkgPath }));
|
|
25
|
+
}
|
|
26
|
+
return cache.get(pkgPath);
|
|
27
|
+
} catch (er) {
|
|
28
|
+
const code = typeof er === "object" && er !== null && "code" in er ? er.code : undefined;
|
|
29
|
+
if (code === "MODULE_NOT_FOUND") {
|
|
30
|
+
if (filename) {
|
|
31
|
+
// Bun doesn't expose workspace packages via `require.resolve`, but tests
|
|
32
|
+
// and tooling can still reference the current package by name.
|
|
33
|
+
const selfPackageJSON = findSelfPackageJSON(pkgName, filename);
|
|
34
|
+
if (selfPackageJSON) {
|
|
35
|
+
return selfPackageJSON;
|
|
36
|
+
}
|
|
37
|
+
const bun = globalThis.Bun;
|
|
38
|
+
if (bun && typeof bun.resolveSync === "function") {
|
|
39
|
+
try {
|
|
40
|
+
const resolved = bun.resolveSync(pkgName, filename);
|
|
41
|
+
if (!cache.has(resolved)) {
|
|
42
|
+
cache.set(resolved, findUp.sync("package.json", { cwd: resolved }));
|
|
43
|
+
}
|
|
44
|
+
return cache.get(resolved);
|
|
45
|
+
} catch {}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (skipPathsOptions && filename) {
|
|
49
|
+
return findPackageJSON(pkgName, null);
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
54
|
+
// See https://github.com/Anber/wyw-in-js/issues/43
|
|
55
|
+
// `require` can't resolve ESM-only packages. We can use the `resolve`
|
|
56
|
+
// package here, but it does not solve all cases because `pkgName`
|
|
57
|
+
// can be an alias and should be resolved by a bundler. However, we can't use
|
|
58
|
+
// `resolve` from a bundler because it is async. The good news is that in that
|
|
59
|
+
// specific case, we can just ignore those packages. For now.
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
throw er;
|
|
63
|
+
}
|
|
72
64
|
}
|
|
73
|
-
//# sourceMappingURL=findPackageJSON.js.map
|
|
65
|
+
//# sourceMappingURL=findPackageJSON.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,kBAAkB;AACpC,SAAS,qBAAqB;AAC9B,OAAO,YAAY;AAEnB,MAAM,QAAQ,IAAI,KAAiC;AACnD,MAAM,cAAc,cAAc,OAAO,KAAK,IAAI;AAElD,SAAS,oBAAoB,SAAiB,UAAkB;CAC9D,MAAM,kBAAkB,OAAO,KAAK,gBAAgB,EAClD,KAAK,QAAQ,SAAS,EACvB,CAAC;AACF,KAAI,CAAC,gBAAiB,QAAO;AAE7B,KAAI;EACF,MAAM,cAAc,KAAK,MAAM,aAAa,iBAAiB,OAAO,CAAC;AACrE,SAAO,aAAa,SAAS,UAAU,kBAAkB;SACnD;AACN,SAAO;;;AAIX,OAAO,SAAS,gBACd,SACA,UACA;;CAEA,MAAM,SAAS,QAAQ,WAAW,SAAS,KAAK,eAAe;CAC/D,MAAM,mBAAmB,UAAU,CAAC,QAAQ,WAAW,IAAI;AAE3D,KAAI;EACF,MAAM,UACJ,YAAY,OAAO,YAAY,WAAW,SAAS,GAC/C,WACA,YAAY,QACV,SACA,WAAW,EAAE,OAAO,CAAC,QAAQ,SAAS,CAAC,EAAE,GAAG,EAAE,CAC/C;AACP,MAAI,CAAC,MAAM,IAAI,QAAQ,EAAE;AACvB,SAAM,IAAI,SAAS,OAAO,KAAK,gBAAgB,EAAE,KAAK,SAAS,CAAC,CAAC;;AAGnE,SAAO,MAAM,IAAI,QAAQ;UAClB,IAAa;EACpB,MAAM,OACJ,OAAO,OAAO,YAAY,OAAO,QAAQ,UAAU,KAC/C,GAAG,OACH;AAEN,MAAI,SAAS,oBAAoB;AAC/B,OAAI,UAAU;;;IAGZ,MAAM,kBAAkB,oBAAoB,SAAS,SAAS;AAC9D,QAAI,iBAAiB;AACnB,YAAO;;IAGT,MAAM,MACJ,WAKA;AACF,QAAI,OAAO,OAAO,IAAI,gBAAgB,YAAY;AAChD,SAAI;MACF,MAAM,WAAW,IAAI,YAAY,SAAS,SAAS;AACnD,UAAI,CAAC,MAAM,IAAI,SAAS,EAAE;AACxB,aAAM,IACJ,UACA,OAAO,KAAK,gBAAgB,EAC1B,KAAK,UACN,CAAC,CACH;;AAGH,aAAO,MAAM,IAAI,SAAS;aACpB;;;AAMZ,OAAI,oBAAoB,UAAU;AAChC,WAAO,gBAAgB,SAAS,KAAK;;AAGvC,UAAO;;AAGT,MAAI,SAAS,iCAAiC;;;;;;;AAO5C,UAAO;;AAGT,QAAM","names":[],"sources":["../src/findPackageJSON.ts"],"version":3,"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, isAbsolute } from 'path';\nimport { createRequire } from 'module';\nimport findUp from 'find-up';\n\nconst cache = new Map<string, string | undefined>();\nconst nodeRequire = createRequire(import.meta.url);\n\nfunction findSelfPackageJSON(pkgName: string, filename: string) {\n const packageJSONPath = findUp.sync('package.json', {\n cwd: dirname(filename),\n });\n if (!packageJSONPath) return undefined;\n\n try {\n const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));\n return packageJSON?.name === pkgName ? packageJSONPath : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function findPackageJSON(\n pkgName: string,\n filename: string | null | undefined\n) {\n // Jest's resolver does not work properly with `moduleNameMapper` when `paths` are defined\n const isJest = Boolean(globalThis.process?.env?.JEST_WORKER_ID);\n const skipPathsOptions = isJest && !pkgName.startsWith('.');\n\n try {\n const pkgPath =\n pkgName === '.' && filename && isAbsolute(filename)\n ? filename\n : nodeRequire.resolve(\n pkgName,\n filename ? { paths: [dirname(filename)] } : {}\n );\n if (!cache.has(pkgPath)) {\n cache.set(pkgPath, findUp.sync('package.json', { cwd: pkgPath }));\n }\n\n return cache.get(pkgPath);\n } catch (er: unknown) {\n const code =\n typeof er === 'object' && er !== null && 'code' in er\n ? er.code\n : undefined;\n\n if (code === 'MODULE_NOT_FOUND') {\n if (filename) {\n // Bun doesn't expose workspace packages via `require.resolve`, but tests\n // and tooling can still reference the current package by name.\n const selfPackageJSON = findSelfPackageJSON(pkgName, filename);\n if (selfPackageJSON) {\n return selfPackageJSON;\n }\n\n const bun = (\n globalThis as typeof globalThis & {\n Bun?: {\n resolveSync?: (specifier: string, from: string) => string;\n };\n }\n ).Bun;\n if (bun && typeof bun.resolveSync === 'function') {\n try {\n const resolved = bun.resolveSync(pkgName, filename);\n if (!cache.has(resolved)) {\n cache.set(\n resolved,\n findUp.sync('package.json', {\n cwd: resolved,\n })\n );\n }\n\n return cache.get(resolved);\n } catch {\n // fall through to the existing resolution heuristics\n }\n }\n }\n\n if (skipPathsOptions && filename) {\n return findPackageJSON(pkgName, null);\n }\n\n return undefined;\n }\n\n if (code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {\n // See https://github.com/Anber/wyw-in-js/issues/43\n // `require` can't resolve ESM-only packages. We can use the `resolve`\n // package here, but it does not solve all cases because `pkgName`\n // can be an alias and should be resolved by a bundler. However, we can't use\n // `resolve` from a bundler because it is async. The good news is that in that\n // specific case, we can just ignore those packages. For now.\n return undefined;\n }\n\n throw er;\n }\n}\n"],"file":"findPackageJSON.js"}
|
package/esm/hasEvalMeta.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export function hasEvalMeta(value) {
|
|
2
|
-
|
|
2
|
+
return typeof value === "object" && value !== null && "__wyw_meta" in value;
|
|
3
3
|
}
|
|
4
|
-
//# sourceMappingURL=hasEvalMeta.js.map
|
|
4
|
+
//# sourceMappingURL=hasEvalMeta.js.map
|
package/esm/hasEvalMeta.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAEA,OAAO,SAAS,YAAY,OAAsC;AAChE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,gBAAgB","names":[],"sources":["../src/hasEvalMeta.ts"],"version":3,"sourcesContent":["import type { WYWEvalMeta } from './types';\n\nexport function hasEvalMeta(value: unknown): value is WYWEvalMeta {\n return typeof value === 'object' && value !== null && '__wyw_meta' in value;\n}\n"],"file":"hasEvalMeta.js"}
|
package/esm/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export { asyncResolveFallback, syncResolve } from
|
|
2
|
-
export { asyncResolverFactory } from
|
|
3
|
-
export { hasEvalMeta } from
|
|
4
|
-
export { findPackageJSON } from
|
|
5
|
-
export { isBoxedPrimitive } from
|
|
6
|
-
export { enableDebug, logger } from
|
|
7
|
-
export { isFeatureEnabled } from
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
|
|
1
|
+
export { asyncResolveFallback, syncResolve } from "./asyncResolveFallback.js";
|
|
2
|
+
export { asyncResolverFactory } from "./asyncResolverFactory.js";
|
|
3
|
+
export { hasEvalMeta } from "./hasEvalMeta.js";
|
|
4
|
+
export { findPackageJSON } from "./findPackageJSON.js";
|
|
5
|
+
export { isBoxedPrimitive } from "./isBoxedPrimitive.js";
|
|
6
|
+
export { enableDebug, logger } from "./logger.js";
|
|
7
|
+
export { isFeatureEnabled } from "./options/isFeatureEnabled.js";
|
|
8
|
+
export { mergeOxcResolverAlias, toNativeResolverAlias } from "./options/nativeResolverOptions.js";
|
|
9
|
+
export { slugify } from "./slugify.js";
|
|
10
|
+
export { ValueType } from "./types.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAEA,SAAS,sBAAsB,mBAAmB;AAClD,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,aAAa,cAAc;AACpC,SAAS,wBAAwB;AACjC,SACE,uBACA,6BACK;AAEP,SAAS,eAAe;AACxB,SAAS,iBAAiB","names":[],"sources":["../src/index.ts"],"version":3,"sourcesContent":["export type { Debugger } from './debugger';\n\nexport { asyncResolveFallback, syncResolve } from './asyncResolveFallback';\nexport { asyncResolverFactory } from './asyncResolverFactory';\nexport { hasEvalMeta } from './hasEvalMeta';\nexport { findPackageJSON } from './findPackageJSON';\nexport { isBoxedPrimitive } from './isBoxedPrimitive';\nexport { enableDebug, logger } from './logger';\nexport { isFeatureEnabled } from './options/isFeatureEnabled';\nexport {\n mergeOxcResolverAlias,\n toNativeResolverAlias,\n} from './options/nativeResolverOptions';\nexport type { NativeResolverAlias } from './options/nativeResolverOptions';\nexport { slugify } from './slugify';\nexport { ValueType } from './types';\n\nexport type { IVariableContext } from './IVariableContext';\nexport type {\n ClassNameSlugVars,\n ClassNameFn,\n CodeRemoverOptions,\n EvalErrorMode,\n EvalOptionsV2,\n EvalRequireMode,\n EvalResolverKind,\n EvalResolverMode,\n EvalRuntime,\n EvalStrategy,\n EvalWarning,\n EvalWarningCode,\n ImportLoader,\n ImportLoaderContext,\n ImportLoaders,\n ImportOverride,\n ImportOverrides,\n OxcOptions,\n TagResolverMeta,\n StrictOptions,\n EvalRule,\n EvaluatorOptions,\n TransformEngineOptions,\n Evaluator,\n FeatureFlag,\n EvaluatorConfig,\n FeatureFlags,\n VariableNameFn,\n} from './options/types';\nexport type {\n Artifact,\n AstExpression,\n AstNode,\n BigIntLiteral,\n BooleanLiteral,\n BuildCodeFrameErrorFn,\n ConstValue,\n DecimalLiteral,\n ExpressionValue,\n FunctionValue,\n Identifier,\n ICSSRule,\n LazyValue,\n Location,\n NullLiteral,\n NumericLiteral,\n Replacement,\n Replacements,\n Rules,\n SourceLocation,\n StringLiteral,\n WYWEvalMeta,\n} from './types';\n"],"file":"index.js"}
|
package/esm/isBoxedPrimitive.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// There is a problem with using boxed numbers and strings in TS,
|
|
2
2
|
// so we cannot just use `instanceof` here
|
|
3
|
-
|
|
4
|
-
const constructors = ['Number', 'String'];
|
|
3
|
+
const constructors = ["Number", "String"];
|
|
5
4
|
export function isBoxedPrimitive(o) {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
if (typeof o !== "object" || o === null) return false;
|
|
6
|
+
return constructors.includes(o.constructor.name) && typeof o?.valueOf() !== "object";
|
|
8
7
|
}
|
|
9
|
-
//# sourceMappingURL=isBoxedPrimitive.js.map
|
|
8
|
+
//# sourceMappingURL=isBoxedPrimitive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":";;AAGA,MAAM,eAAe,CAAC,UAAU,SAAS;AACzC,OAAO,SAAS,iBAAiB,GAAkC;AACjE,KAAI,OAAO,MAAM,YAAY,MAAM,KAAM,QAAO;AAChD,QACE,aAAa,SAAS,EAAE,YAAY,KAAK,IACzC,OAAO,GAAG,SAAS,KAAK","names":[],"sources":["../src/isBoxedPrimitive.ts"],"version":3,"sourcesContent":["// There is a problem with using boxed numbers and strings in TS,\n// so we cannot just use `instanceof` here\n\nconst constructors = ['Number', 'String'];\nexport function isBoxedPrimitive(o: unknown): o is number | string {\n if (typeof o !== 'object' || o === null) return false;\n return (\n constructors.includes(o.constructor.name) &&\n typeof o?.valueOf() !== 'object'\n );\n}\n"],"file":"isBoxedPrimitive.js"}
|
package/esm/logger.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import genericDebug from
|
|
2
|
-
const BASE_NAMESPACE =
|
|
1
|
+
import genericDebug from "debug";
|
|
2
|
+
const BASE_NAMESPACE = "wyw-in-js";
|
|
3
3
|
export const logger = genericDebug(BASE_NAMESPACE);
|
|
4
4
|
const loggers = new Map();
|
|
5
5
|
function gerOrCreate(namespace) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
if (!namespace) return logger;
|
|
7
|
+
const lastIndexOf = namespace.lastIndexOf(":");
|
|
8
|
+
if (!loggers.has(namespace)) {
|
|
9
|
+
loggers.set(namespace, gerOrCreate(namespace.substring(0, lastIndexOf)).extend(namespace.substring(lastIndexOf + 1)));
|
|
10
|
+
}
|
|
11
|
+
return loggers.get(namespace);
|
|
12
12
|
}
|
|
13
|
-
genericDebug.formatters.r = ref => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
genericDebug.formatters.r = (ref) => {
|
|
14
|
+
const namespace = typeof ref === "string" ? ref : ref.namespace;
|
|
15
|
+
const text = typeof ref === "string" ? namespace : ref.text ?? namespace;
|
|
16
|
+
const color = parseInt(gerOrCreate(namespace).color, 10);
|
|
17
|
+
const colorCode = `\u001B[3${color < 8 ? color : `8;5;${color}`}`;
|
|
18
|
+
return `${colorCode};1m${text}\u001B[0m`;
|
|
19
19
|
};
|
|
20
20
|
genericDebug.formatters.f = function f(fn) {
|
|
21
|
-
|
|
21
|
+
return JSON.stringify(fn());
|
|
22
22
|
};
|
|
23
23
|
export function enableDebug(namespace = `${BASE_NAMESPACE}:*`) {
|
|
24
|
-
|
|
24
|
+
genericDebug.enable(namespace);
|
|
25
25
|
}
|
|
26
|
-
//# sourceMappingURL=logger.js.map
|
|
26
|
+
//# sourceMappingURL=logger.js.map
|
package/esm/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,OAAO,kBAAkB;AAIzB,MAAM,iBAAiB;AAEvB,OAAO,MAAM,SAAmB,aAAa,eAAe;AAE5D,MAAM,UAAU,IAAI,KAAuB;AAE3C,SAAS,YAAY,WAAgD;AACnE,KAAI,CAAC,UAAW,QAAO;CACvB,MAAM,cAAc,UAAU,YAAY,IAAI;AAC9C,KAAI,CAAC,QAAQ,IAAI,UAAU,EAAE;AAC3B,UAAQ,IACN,WACA,YAAY,UAAU,UAAU,GAAG,YAAY,CAAC,CAAC,OAC/C,UAAU,UAAU,cAAc,EAAE,CACrC,CACF;;AAGH,QAAO,QAAQ,IAAI,UAAU;;AAG/B,aAAa,WAAW,KACtB,QACG;CACH,MAAM,YAAY,OAAO,QAAQ,WAAW,MAAM,IAAI;CACtD,MAAM,OAAO,OAAO,QAAQ,WAAW,YAAY,IAAI,QAAQ;CAC/D,MAAM,QAAQ,SAAS,YAAY,UAAU,CAAC,OAAO,GAAG;CACxD,MAAM,YAAY,WAAW,QAAQ,IAAI,QAAQ,OAAO;AACxD,QAAO,GAAG,UAAU,KAAK,KAAK;;AAGhC,aAAa,WAAW,IAAI,SAAS,EAAE,IAAmB;AACxD,QAAO,KAAK,UAAU,IAAI,CAAC;;AAG7B,OAAO,SAAS,YAAY,YAAY,GAAG,eAAe,KAAK;AAC7D,cAAa,OAAO,UAAU","names":[],"sources":["../src/logger.ts"],"version":3,"sourcesContent":["import genericDebug from 'debug';\n\nimport type { Debugger } from './debugger';\n\nconst BASE_NAMESPACE = 'wyw-in-js';\n\nexport const logger: Debugger = genericDebug(BASE_NAMESPACE);\n\nconst loggers = new Map<string, Debugger>();\n\nfunction gerOrCreate(namespace: string | null | undefined): Debugger {\n if (!namespace) return logger;\n const lastIndexOf = namespace.lastIndexOf(':');\n if (!loggers.has(namespace)) {\n loggers.set(\n namespace,\n gerOrCreate(namespace.substring(0, lastIndexOf)).extend(\n namespace.substring(lastIndexOf + 1)\n )\n );\n }\n\n return loggers.get(namespace)!;\n}\n\ngenericDebug.formatters.r = (\n ref: string | { namespace: string; text?: string }\n) => {\n const namespace = typeof ref === 'string' ? ref : ref.namespace;\n const text = typeof ref === 'string' ? namespace : ref.text ?? namespace;\n const color = parseInt(gerOrCreate(namespace).color, 10);\n const colorCode = `\\u001B[3${color < 8 ? color : `8;5;${color}`}`;\n return `${colorCode};1m${text}\\u001B[0m`;\n};\n\ngenericDebug.formatters.f = function f(fn: () => unknown) {\n return JSON.stringify(fn());\n};\n\nexport function enableDebug(namespace = `${BASE_NAMESPACE}:*`) {\n genericDebug.enable(namespace);\n}\n"],"file":"logger.js"}
|
|
@@ -1,30 +1,25 @@
|
|
|
1
|
-
import { Minimatch } from
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
-
|
|
1
|
+
import { Minimatch } from "minimatch";
|
|
5
2
|
const cachedMatchers = new Map();
|
|
6
3
|
export const isFeatureEnabled = (features, featureName, filename) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return [matcher[0], matcher[1].match(filename)];
|
|
28
|
-
}).reduce((acc, [negated, match]) => negated ? acc && match : acc || match, false);
|
|
4
|
+
const value = features?.[featureName] ?? false;
|
|
5
|
+
if (typeof value === "boolean") {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
// Fast check for glob patterns
|
|
9
|
+
if (value === "*" || value === "**/*") {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
const array = Array.isArray(value) ? value : [value];
|
|
13
|
+
/**
|
|
14
|
+
* Check rule by rule like .gitignore
|
|
15
|
+
*/
|
|
16
|
+
return array.map((pattern) => {
|
|
17
|
+
let matcher = cachedMatchers.get(pattern);
|
|
18
|
+
if (!matcher) {
|
|
19
|
+
matcher = [pattern.startsWith("!"), new Minimatch(pattern)];
|
|
20
|
+
cachedMatchers.set(pattern, matcher);
|
|
21
|
+
}
|
|
22
|
+
return [matcher[0], matcher[1].match(filename)];
|
|
23
|
+
}).reduce((acc, [negated, match]) => negated ? acc && match : acc || match, false);
|
|
29
24
|
};
|
|
30
|
-
//# sourceMappingURL=isFeatureEnabled.js.map
|
|
25
|
+
//# sourceMappingURL=isFeatureEnabled.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SAAS,iBAAiB;AAO1B,MAAM,iBAAiB,IAAI,KAGxB;AAEH,OAAO,MAAM,oBACX,UAKA,aACA,aACG;CACH,MAAM,QAAQ,WAAW,gBAAgB;AACzC,KAAI,OAAO,UAAU,WAAW;AAC9B,SAAO;;;AAIT,KAAI,UAAU,OAAO,UAAU,QAAQ;AACrC,SAAO;;CAGT,MAAM,QAAkB,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM;;;;AAK9D,QAAO,MACJ,KAAK,YAAY;EAChB,IAAI,UAAU,eAAe,IAAI,QAAQ;AACzC,MAAI,CAAC,SAAS;AACZ,aAAU,CAAC,QAAQ,WAAW,IAAI,EAAE,IAAI,UAAU,QAAQ,CAAC;AAC3D,kBAAe,IAAI,SAAS,QAAQ;;AAGtC,SAAO,CAAC,QAAQ,IAAI,QAAQ,GAAG,MAAM,SAAS,CAAC;GAC/C,CACD,QACE,KAAK,CAAC,SAAS,WAAY,UAAU,OAAO,QAAQ,OAAO,OAC5D,MACD","names":[],"sources":["../../src/options/isFeatureEnabled.ts"],"version":3,"sourcesContent":["import { Minimatch } from 'minimatch';\n\nimport type { FeatureFlag } from './types';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype NoInfer<T> = [T][T extends any ? 0 : never];\n\nconst cachedMatchers = new Map<\n string,\n [nagated: boolean, matcher: Minimatch]\n>();\n\nexport const isFeatureEnabled = <T extends string>(\n features:\n | {\n [K in T]?: FeatureFlag;\n }\n | undefined,\n featureName: NoInfer<T>,\n filename: string\n) => {\n const value = features?.[featureName] ?? false;\n if (typeof value === 'boolean') {\n return value;\n }\n\n // Fast check for glob patterns\n if (value === '*' || value === '**/*') {\n return true;\n }\n\n const array: string[] = Array.isArray(value) ? value : [value];\n\n /**\n * Check rule by rule like .gitignore\n */\n return array\n .map((pattern) => {\n let matcher = cachedMatchers.get(pattern);\n if (!matcher) {\n matcher = [pattern.startsWith('!'), new Minimatch(pattern)];\n cachedMatchers.set(pattern, matcher);\n }\n\n return [matcher[0], matcher[1].match(filename)];\n })\n .reduce(\n (acc, [negated, match]) => (negated ? acc && match : acc || match),\n false\n );\n};\n"],"file":"isFeatureEnabled.js"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const isNativeResolverAlias = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2
|
+
const toAliasTargets = (replacement) => {
|
|
3
|
+
if (typeof replacement === "string") {
|
|
4
|
+
return [replacement];
|
|
5
|
+
}
|
|
6
|
+
if (Array.isArray(replacement) && replacement.every((item) => typeof item === "string")) {
|
|
7
|
+
return replacement;
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
export const toNativeResolverAlias = (alias) => {
|
|
12
|
+
const nativeAlias = {};
|
|
13
|
+
const entries = Array.isArray(alias) ? alias : isNativeResolverAlias(alias) ? Object.entries(alias).map(([find, replacement]) => ({
|
|
14
|
+
find,
|
|
15
|
+
replacement
|
|
16
|
+
})) : [];
|
|
17
|
+
entries.forEach((rawEntry) => {
|
|
18
|
+
if (!isNativeResolverAlias(rawEntry)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const entry = rawEntry;
|
|
22
|
+
const find = "find" in entry ? entry.find : entry.name;
|
|
23
|
+
const replacement = "replacement" in entry ? entry.replacement : entry.alias;
|
|
24
|
+
const targets = toAliasTargets(replacement);
|
|
25
|
+
if (typeof find !== "string" || !targets) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
nativeAlias[find] = targets;
|
|
29
|
+
});
|
|
30
|
+
return nativeAlias;
|
|
31
|
+
};
|
|
32
|
+
export const mergeOxcResolverAlias = (oxcOptions, bundlerAlias) => {
|
|
33
|
+
if (Object.keys(bundlerAlias).length === 0) {
|
|
34
|
+
return oxcOptions;
|
|
35
|
+
}
|
|
36
|
+
const resolver = oxcOptions?.resolver ?? {};
|
|
37
|
+
const configuredAlias = isNativeResolverAlias(resolver.alias) ? resolver.alias : {};
|
|
38
|
+
return {
|
|
39
|
+
...oxcOptions,
|
|
40
|
+
resolver: {
|
|
41
|
+
...resolver,
|
|
42
|
+
alias: {
|
|
43
|
+
...bundlerAlias,
|
|
44
|
+
...configuredAlias
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=nativeResolverOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAcA,MAAM,yBAAyB,UAC7B,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;AAEtE,MAAM,kBACJ,gBAC4C;AAC5C,KAAI,OAAO,gBAAgB,UAAU;AACnC,SAAO,CAAC,YAAY;;AAGtB,KACE,MAAM,QAAQ,YAAY,IAC1B,YAAY,OAAO,SAAS,OAAO,SAAS,SAAS,EACrD;AACA,SAAO;;AAGT,QAAO;;AAGT,OAAO,MAAM,yBACX,UACwB;CACxB,MAAM,cAAmC,EAAE;CAE3C,MAAM,UAAU,MAAM,QAAQ,MAAM,GAChC,QACA,sBAAsB,MAAM,GAC1B,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,MAAM,kBAAkB;EAClD;EACA;EACD,EAAE,GACH,EAAE;AAER,SAAQ,SAAS,aAAa;AAC5B,MAAI,CAAC,sBAAsB,SAAS,EAAE;AACpC;;EAGF,MAAM,QAAQ;EACd,MAAM,OAAO,UAAU,QAAQ,MAAM,OAAO,MAAM;EAClD,MAAM,cACJ,iBAAiB,QAAQ,MAAM,cAAc,MAAM;EACrD,MAAM,UAAU,eAAe,YAAY;AAE3C,MAAI,OAAO,SAAS,YAAY,CAAC,SAAS;AACxC;;AAGF,cAAY,QAAQ;GACpB;AAEF,QAAO;;AAGT,OAAO,MAAM,yBACX,YACA,iBAC2B;AAC3B,KAAI,OAAO,KAAK,aAAa,CAAC,WAAW,GAAG;AAC1C,SAAO;;CAGT,MAAM,WAAW,YAAY,YAAY,EAAE;CAC3C,MAAM,kBAAkB,sBAAsB,SAAS,MAAM,GACzD,SAAS,QACT,EAAE;AAEN,QAAO;EACL,GAAG;EACH,UAAU;GACR,GAAG;GACH,OAAO;IACL,GAAG;IACH,GAAG;IACJ;GACF;EACF","names":[],"sources":["../../src/options/nativeResolverOptions.ts"],"version":3,"sourcesContent":["import type { OxcOptions } from './types';\n\nexport type NativeResolverAlias = Record<\n string,\n Array<string | undefined | null>\n>;\n\ntype AliasEntry = {\n alias?: unknown;\n find?: unknown;\n name?: unknown;\n replacement?: unknown;\n};\n\nconst isNativeResolverAlias = (value: unknown): value is NativeResolverAlias =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst toAliasTargets = (\n replacement: unknown\n): Array<string | undefined | null> | null => {\n if (typeof replacement === 'string') {\n return [replacement];\n }\n\n if (\n Array.isArray(replacement) &&\n replacement.every((item) => typeof item === 'string')\n ) {\n return replacement;\n }\n\n return null;\n};\n\nexport const toNativeResolverAlias = (\n alias: unknown\n): NativeResolverAlias => {\n const nativeAlias: NativeResolverAlias = {};\n\n const entries = Array.isArray(alias)\n ? alias\n : isNativeResolverAlias(alias)\n ? Object.entries(alias).map(([find, replacement]) => ({\n find,\n replacement,\n }))\n : [];\n\n entries.forEach((rawEntry) => {\n if (!isNativeResolverAlias(rawEntry)) {\n return;\n }\n\n const entry = rawEntry as AliasEntry;\n const find = 'find' in entry ? entry.find : entry.name;\n const replacement =\n 'replacement' in entry ? entry.replacement : entry.alias;\n const targets = toAliasTargets(replacement);\n\n if (typeof find !== 'string' || !targets) {\n return;\n }\n\n nativeAlias[find] = targets;\n });\n\n return nativeAlias;\n};\n\nexport const mergeOxcResolverAlias = (\n oxcOptions: OxcOptions | undefined,\n bundlerAlias: NativeResolverAlias\n): OxcOptions | undefined => {\n if (Object.keys(bundlerAlias).length === 0) {\n return oxcOptions;\n }\n\n const resolver = oxcOptions?.resolver ?? {};\n const configuredAlias = isNativeResolverAlias(resolver.alias)\n ? resolver.alias\n : {};\n\n return {\n ...oxcOptions,\n resolver: {\n ...resolver,\n alias: {\n ...bundlerAlias,\n ...configuredAlias,\n },\n },\n };\n};\n"],"file":"nativeResolverOptions.js"}
|
package/esm/options/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
2
|
+
//# sourceMappingURL=types.js.map
|