@wyw-in-js/shared 1.1.0 → 2.0.0-alpha.0
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 +10 -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/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 +2 -2
- package/types/index.js +9 -23
- package/types/isBoxedPrimitive.js +1 -4
- package/types/logger.js +7 -14
- package/types/options/isFeatureEnabled.js +3 -7
- package/types/options/types.d.ts +78 -8
- 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/slugify.js
CHANGED
|
@@ -1,62 +1,60 @@
|
|
|
1
1
|
/* eslint-disable no-plusplus, no-bitwise, default-case, no-param-reassign, prefer-destructuring */
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
* This file contains a utility to generate hashes to be used as generated class names
|
|
4
|
+
*/
|
|
6
5
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
* murmurhash2 via https://gist.github.com/raycmorgan/588423
|
|
7
|
+
*/
|
|
10
8
|
function UInt32(str, pos) {
|
|
11
|
-
|
|
9
|
+
return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8) + (str.charCodeAt(pos++) << 16) + (str.charCodeAt(pos) << 24);
|
|
12
10
|
}
|
|
13
11
|
function UInt16(str, pos) {
|
|
14
|
-
|
|
12
|
+
return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8);
|
|
15
13
|
}
|
|
16
14
|
function Umul32(n, m) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
n |= 0;
|
|
16
|
+
m |= 0;
|
|
17
|
+
const nlo = n & 65535;
|
|
18
|
+
const nhi = n >>> 16;
|
|
19
|
+
return nlo * m + ((nhi * m & 65535) << 16) | 0;
|
|
22
20
|
}
|
|
23
21
|
function doHash(str, seed = 0) {
|
|
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
|
-
|
|
22
|
+
const m = 1540483477;
|
|
23
|
+
const r = 24;
|
|
24
|
+
let h = seed ^ str.length;
|
|
25
|
+
let length = str.length;
|
|
26
|
+
let currentIndex = 0;
|
|
27
|
+
while (length >= 4) {
|
|
28
|
+
let k = UInt32(str, currentIndex);
|
|
29
|
+
k = Umul32(k, m);
|
|
30
|
+
k ^= k >>> r;
|
|
31
|
+
k = Umul32(k, m);
|
|
32
|
+
h = Umul32(h, m);
|
|
33
|
+
h ^= k;
|
|
34
|
+
currentIndex += 4;
|
|
35
|
+
length -= 4;
|
|
36
|
+
}
|
|
37
|
+
switch (length) {
|
|
38
|
+
case 3:
|
|
39
|
+
h ^= UInt16(str, currentIndex);
|
|
40
|
+
h ^= str.charCodeAt(currentIndex + 2) << 16;
|
|
41
|
+
h = Umul32(h, m);
|
|
42
|
+
break;
|
|
43
|
+
case 2:
|
|
44
|
+
h ^= UInt16(str, currentIndex);
|
|
45
|
+
h = Umul32(h, m);
|
|
46
|
+
break;
|
|
47
|
+
case 1:
|
|
48
|
+
h ^= str.charCodeAt(currentIndex);
|
|
49
|
+
h = Umul32(h, m);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
h ^= h >>> 13;
|
|
53
|
+
h = Umul32(h, m);
|
|
54
|
+
h ^= h >>> 15;
|
|
55
|
+
return h >>> 0;
|
|
58
56
|
}
|
|
59
57
|
export function slugify(code) {
|
|
60
|
-
|
|
58
|
+
return doHash(code).toString(36);
|
|
61
59
|
}
|
|
62
|
-
//# sourceMappingURL=slugify.js.map
|
|
60
|
+
//# sourceMappingURL=slugify.js.map
|
package/esm/slugify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":";;;;;;;AASA,SAAS,OAAO,KAAa,KAAa;AACxC,QACE,IAAI,WAAW,MAAM,IACpB,IAAI,WAAW,MAAM,IAAI,MACzB,IAAI,WAAW,MAAM,IAAI,OACzB,IAAI,WAAW,IAAI,IAAI;;AAI5B,SAAS,OAAO,KAAa,KAAa;AACxC,QAAO,IAAI,WAAW,MAAM,IAAI,IAAI,WAAW,MAAM,IAAI;;AAG3D,SAAS,OAAO,GAAW,GAAW;AACpC,MAAK;AACL,MAAK;CACL,MAAM,MAAM,IAAI;CAChB,MAAM,MAAM,MAAM;AAClB,QAAQ,MAAM,MAAO,MAAM,IAAK,UAAW,MAAO;;AAGpD,SAAS,OAAO,KAAa,OAAO,GAAG;CACrC,MAAM,IAAI;CACV,MAAM,IAAI;CACV,IAAI,IAAI,OAAO,IAAI;CACnB,IAAI,SAAS,IAAI;CACjB,IAAI,eAAe;AAEnB,QAAO,UAAU,GAAG;EAClB,IAAI,IAAI,OAAO,KAAK,aAAa;AAEjC,MAAI,OAAO,GAAG,EAAE;AAChB,OAAK,MAAM;AACX,MAAI,OAAO,GAAG,EAAE;AAEhB,MAAI,OAAO,GAAG,EAAE;AAChB,OAAK;AAEL,kBAAgB;AAChB,YAAU;;AAGZ,SAAQ,QAAR;EACE,KAAK;AACH,QAAK,OAAO,KAAK,aAAa;AAC9B,QAAK,IAAI,WAAW,eAAe,EAAE,IAAI;AACzC,OAAI,OAAO,GAAG,EAAE;AAChB;EAEF,KAAK;AACH,QAAK,OAAO,KAAK,aAAa;AAC9B,OAAI,OAAO,GAAG,EAAE;AAChB;EAEF,KAAK;AACH,QAAK,IAAI,WAAW,aAAa;AACjC,OAAI,OAAO,GAAG,EAAE;AAChB;;AAGJ,MAAK,MAAM;AACX,KAAI,OAAO,GAAG,EAAE;AAChB,MAAK,MAAM;AAEX,QAAO,MAAM;;AAGf,OAAO,SAAS,QAAQ,MAAc;AACpC,QAAO,OAAO,KAAK,CAAC,SAAS,GAAG","names":[],"sources":["../src/slugify.ts"],"version":3,"sourcesContent":["/* eslint-disable no-plusplus, no-bitwise, default-case, no-param-reassign, prefer-destructuring */\n/**\n * This file contains a utility to generate hashes to be used as generated class names\n */\n\n/**\n * murmurhash2 via https://gist.github.com/raycmorgan/588423\n */\n\nfunction UInt32(str: string, pos: number) {\n return (\n str.charCodeAt(pos++) +\n (str.charCodeAt(pos++) << 8) +\n (str.charCodeAt(pos++) << 16) +\n (str.charCodeAt(pos) << 24)\n );\n}\n\nfunction UInt16(str: string, pos: number) {\n return str.charCodeAt(pos++) + (str.charCodeAt(pos++) << 8);\n}\n\nfunction Umul32(n: number, m: number) {\n n |= 0;\n m |= 0;\n const nlo = n & 0xffff;\n const nhi = n >>> 16;\n return (nlo * m + (((nhi * m) & 0xffff) << 16)) | 0;\n}\n\nfunction doHash(str: string, seed = 0) {\n const m = 0x5bd1e995;\n const r = 24;\n let h = seed ^ str.length;\n let length = str.length;\n let currentIndex = 0;\n\n while (length >= 4) {\n let k = UInt32(str, currentIndex);\n\n k = Umul32(k, m);\n k ^= k >>> r;\n k = Umul32(k, m);\n\n h = Umul32(h, m);\n h ^= k;\n\n currentIndex += 4;\n length -= 4;\n }\n\n switch (length) {\n case 3:\n h ^= UInt16(str, currentIndex);\n h ^= str.charCodeAt(currentIndex + 2) << 16;\n h = Umul32(h, m);\n break;\n\n case 2:\n h ^= UInt16(str, currentIndex);\n h = Umul32(h, m);\n break;\n\n case 1:\n h ^= str.charCodeAt(currentIndex);\n h = Umul32(h, m);\n break;\n }\n\n h ^= h >>> 13;\n h = Umul32(h, m);\n h ^= h >>> 15;\n\n return h >>> 0;\n}\n\nexport function slugify(code: string) {\n return doHash(code).toString(36);\n}\n"],"file":"slugify.js"}
|
package/esm/types.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
export let ValueType =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export let ValueType = /* @__PURE__ */ function(ValueType) {
|
|
2
|
+
ValueType[ValueType["LAZY"] = 0] = "LAZY";
|
|
3
|
+
ValueType[ValueType["FUNCTION"] = 1] = "FUNCTION";
|
|
4
|
+
ValueType[ValueType["CONST"] = 2] = "CONST";
|
|
5
|
+
return ValueType;
|
|
6
6
|
}({});
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* CSS-related types
|
|
10
|
-
*/
|
|
11
|
-
//# sourceMappingURL=types.js.map
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
package/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAOA,OAAO,IAAK,YAAL;AACL;AACA;AACA;;KACD","names":[],"sources":["../src/types.ts"],"version":3,"sourcesContent":["export type Artifact = [name: string, data: unknown];\n\nexport type BuildCodeFrameErrorFn = <TError extends Error>(\n msg: string,\n Error?: new (innerMsg: string) => TError\n) => TError;\n\nexport enum ValueType {\n LAZY,\n FUNCTION,\n CONST,\n}\n\nexport type SourceLocation = {\n end: Location;\n filename?: string;\n identifierName?: string | null;\n start: Location;\n};\n\nexport type AstNode = {\n end?: number | null;\n loc?: SourceLocation | null;\n start?: number | null;\n type: string;\n};\n\nexport type AstExpression = AstNode;\n\nexport type Identifier = AstExpression & {\n name: string;\n type: 'Identifier';\n};\n\nexport type StringLiteral = AstExpression & {\n type: 'StringLiteral';\n value: string;\n};\n\nexport type NumericLiteral = AstExpression & {\n type: 'NumericLiteral';\n value: number;\n};\n\nexport type NullLiteral = AstExpression & {\n type: 'NullLiteral';\n};\n\nexport type BooleanLiteral = AstExpression & {\n type: 'BooleanLiteral';\n value: boolean;\n};\n\nexport type BigIntLiteral = AstExpression & {\n type: 'BigIntLiteral';\n value: bigint | string;\n};\n\nexport type DecimalLiteral = AstExpression & {\n type: 'DecimalLiteral';\n value: string;\n};\n\nexport type LazyValue = {\n buildCodeFrameError: BuildCodeFrameErrorFn;\n ex: Identifier;\n importedFrom?: string[];\n kind: ValueType.LAZY;\n source: string;\n};\n\nexport type FunctionValue = {\n buildCodeFrameError: BuildCodeFrameErrorFn;\n ex: Identifier;\n importedFrom?: string[];\n kind: ValueType.FUNCTION;\n source: string;\n};\n\nexport type ConstValue = {\n buildCodeFrameError: BuildCodeFrameErrorFn;\n ex:\n | StringLiteral\n | NumericLiteral\n | NullLiteral\n | BooleanLiteral\n | BigIntLiteral\n | DecimalLiteral;\n kind: ValueType.CONST;\n source: string;\n value: string | number | boolean | null;\n};\n\nexport type ExpressionValue = LazyValue | FunctionValue | ConstValue;\n\nexport type WYWEvalMeta = {\n __wyw_meta: {\n className: string;\n extends: WYWEvalMeta;\n };\n};\n\nexport type Location = {\n column: number;\n line: number;\n};\n\nexport type Replacement = {\n length: number;\n original: { end: Location; start: Location };\n};\n\nexport type Replacements = Array<Replacement>;\n\n/**\n * CSS-related types\n */\n\nexport interface ICSSRule {\n atom?: boolean;\n className: string;\n cssText: string;\n displayName: string;\n start: Location | null | undefined;\n}\n\nexport type Rules = Record<string, ICSSRule>;\n"],"file":"types.js"}
|
package/package.json
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/shared",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"dependencies": {
|
|
5
6
|
"debug": "^4.3.4",
|
|
6
7
|
"find-up": "^5.0.0",
|
|
7
8
|
"minimatch": "^9.0.3"
|
|
8
9
|
},
|
|
9
10
|
"devDependencies": {
|
|
10
|
-
"@babel/types": "^7.23.5",
|
|
11
|
-
"@types/babel__core": "^7.20.5",
|
|
12
11
|
"@types/debug": "^4.1.9",
|
|
13
|
-
"@types/node": "^
|
|
14
|
-
"@wyw-in-js/babel-config": "workspace:*",
|
|
12
|
+
"@types/node": "^22.0.0",
|
|
15
13
|
"@wyw-in-js/eslint-config": "workspace:*",
|
|
16
14
|
"@wyw-in-js/ts-config": "workspace:*",
|
|
17
15
|
"typescript": "^5.2.2"
|
|
18
16
|
},
|
|
19
17
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
18
|
+
"node": ">=22.0.0"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./types/index.d.ts",
|
|
23
|
+
"default": "./esm/index.js"
|
|
24
|
+
}
|
|
21
25
|
},
|
|
22
26
|
"files": [
|
|
23
27
|
"esm/",
|
|
24
|
-
"lib/",
|
|
25
28
|
"types/"
|
|
26
29
|
],
|
|
27
30
|
"license": "MIT",
|
|
28
|
-
"main": "
|
|
31
|
+
"main": "esm/index.js",
|
|
29
32
|
"module": "esm/index.js",
|
|
30
33
|
"publishConfig": {
|
|
31
34
|
"access": "public"
|
|
32
35
|
},
|
|
33
36
|
"scripts": {
|
|
34
|
-
"build:esm": "
|
|
35
|
-
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
37
|
+
"build:esm": "node ../../scripts/build-esm-oxc.mjs",
|
|
36
38
|
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
|
|
37
39
|
"lint": "eslint --ext .js,.ts .",
|
|
38
40
|
"test": "bun test src"
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.asyncResolveFallback = exports.syncResolve = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
8
4
|
const safeResolve = (name, where) => {
|
|
9
5
|
try {
|
|
10
|
-
return
|
|
6
|
+
return nodeRequire.resolve(name, {
|
|
11
7
|
paths: where,
|
|
12
8
|
});
|
|
13
9
|
}
|
|
@@ -20,8 +16,8 @@ const suffixes = ['.js', '.ts', '.jsx', '.tsx'].reduce((acc, ext) => {
|
|
|
20
16
|
acc.push(ext);
|
|
21
17
|
return acc;
|
|
22
18
|
}, []);
|
|
23
|
-
const syncResolve = (what, importer, stack) => {
|
|
24
|
-
const where = [importer, ...stack].map((p) =>
|
|
19
|
+
export const syncResolve = (what, importer, stack) => {
|
|
20
|
+
const where = [importer, ...stack].map((p) => path.dirname(p));
|
|
25
21
|
const resolved = safeResolve(what, where);
|
|
26
22
|
if (!(resolved instanceof Error)) {
|
|
27
23
|
return resolved;
|
|
@@ -37,9 +33,7 @@ const syncResolve = (what, importer, stack) => {
|
|
|
37
33
|
}
|
|
38
34
|
throw resolved;
|
|
39
35
|
};
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const resolved = (0, exports.syncResolve)(what, importer, stack);
|
|
36
|
+
export const asyncResolveFallback = (what, importer, stack) => {
|
|
37
|
+
const resolved = syncResolve(what, importer, stack);
|
|
43
38
|
return Promise.resolve(resolved);
|
|
44
39
|
};
|
|
45
|
-
exports.asyncResolveFallback = asyncResolveFallback;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.asyncResolverFactory = void 0;
|
|
4
|
-
const asyncResolverFactory = (onResolve, mapper) => {
|
|
1
|
+
export const asyncResolverFactory = (onResolve, mapper) => {
|
|
5
2
|
const memoizedSyncResolve = new WeakMap();
|
|
6
3
|
return (resolveFn) => {
|
|
7
4
|
if (!memoizedSyncResolve.has(resolveFn)) {
|
|
@@ -11,4 +8,3 @@ const asyncResolverFactory = (onResolve, mapper) => {
|
|
|
11
8
|
return memoizedSyncResolve.get(resolveFn);
|
|
12
9
|
};
|
|
13
10
|
};
|
|
14
|
-
exports.asyncResolverFactory = asyncResolverFactory;
|
package/types/debugger.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/types/findPackageJSON.js
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.findPackageJSON = findPackageJSON;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const find_up_1 = __importDefault(require("find-up"));
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { dirname, isAbsolute } from 'path';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import findUp from 'find-up';
|
|
10
5
|
const cache = new Map();
|
|
6
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
11
7
|
function findSelfPackageJSON(pkgName, filename) {
|
|
12
|
-
const packageJSONPath =
|
|
13
|
-
cwd:
|
|
8
|
+
const packageJSONPath = findUp.sync('package.json', {
|
|
9
|
+
cwd: dirname(filename),
|
|
14
10
|
});
|
|
15
11
|
if (!packageJSONPath)
|
|
16
12
|
return undefined;
|
|
17
13
|
try {
|
|
18
|
-
const packageJSON = JSON.parse(
|
|
14
|
+
const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));
|
|
19
15
|
return packageJSON?.name === pkgName ? packageJSONPath : undefined;
|
|
20
16
|
}
|
|
21
17
|
catch {
|
|
22
18
|
return undefined;
|
|
23
19
|
}
|
|
24
20
|
}
|
|
25
|
-
function findPackageJSON(pkgName, filename) {
|
|
21
|
+
export function findPackageJSON(pkgName, filename) {
|
|
26
22
|
// Jest's resolver does not work properly with `moduleNameMapper` when `paths` are defined
|
|
27
23
|
const isJest = Boolean(globalThis.process?.env?.JEST_WORKER_ID);
|
|
28
24
|
const skipPathsOptions = isJest && !pkgName.startsWith('.');
|
|
29
25
|
try {
|
|
30
|
-
const pkgPath = pkgName === '.' && filename &&
|
|
26
|
+
const pkgPath = pkgName === '.' && filename && isAbsolute(filename)
|
|
31
27
|
? filename
|
|
32
|
-
:
|
|
28
|
+
: nodeRequire.resolve(pkgName, filename ? { paths: [dirname(filename)] } : {});
|
|
33
29
|
if (!cache.has(pkgPath)) {
|
|
34
|
-
cache.set(pkgPath,
|
|
30
|
+
cache.set(pkgPath, findUp.sync('package.json', { cwd: pkgPath }));
|
|
35
31
|
}
|
|
36
32
|
return cache.get(pkgPath);
|
|
37
33
|
}
|
|
@@ -52,7 +48,7 @@ function findPackageJSON(pkgName, filename) {
|
|
|
52
48
|
try {
|
|
53
49
|
const resolved = bun.resolveSync(pkgName, filename);
|
|
54
50
|
if (!cache.has(resolved)) {
|
|
55
|
-
cache.set(resolved,
|
|
51
|
+
cache.set(resolved, findUp.sync('package.json', {
|
|
56
52
|
cwd: resolved,
|
|
57
53
|
}));
|
|
58
54
|
}
|
package/types/hasEvalMeta.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasEvalMeta = hasEvalMeta;
|
|
4
|
-
function hasEvalMeta(value) {
|
|
1
|
+
export function hasEvalMeta(value) {
|
|
5
2
|
return typeof value === 'object' && value !== null && '__wyw_meta' in value;
|
|
6
3
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export { isFeatureEnabled } from './options/isFeatureEnabled';
|
|
|
9
9
|
export { slugify } from './slugify';
|
|
10
10
|
export { ValueType } from './types';
|
|
11
11
|
export type { IVariableContext } from './IVariableContext';
|
|
12
|
-
export type { ClassNameSlugVars, ClassNameFn, CodeRemoverOptions, ImportLoader, ImportLoaderContext, ImportLoaders, ImportOverride, ImportOverrides, TagResolverMeta, StrictOptions, EvalRule, Evaluator, FeatureFlag, EvaluatorConfig, FeatureFlags, VariableNameFn, } from './options/types';
|
|
13
|
-
export type { Artifact, BuildCodeFrameErrorFn, ConstValue, ExpressionValue, FunctionValue, ICSSRule, LazyValue, Location, Replacement, Replacements, Rules, WYWEvalMeta, } from './types';
|
|
12
|
+
export type { ClassNameSlugVars, ClassNameFn, CodeRemoverOptions, EvalOptionsV2, EvalRequireMode, EvalResolverKind, EvalResolverMode, EvalWarning, EvalWarningCode, ImportLoader, ImportLoaderContext, ImportLoaders, ImportOverride, ImportOverrides, OxcOptions, TagResolverMeta, StrictOptions, EvalRule, EvaluatorOptions, TransformEngineOptions, Evaluator, FeatureFlag, EvaluatorConfig, FeatureFlags, VariableNameFn, } from './options/types';
|
|
13
|
+
export type { Artifact, AstExpression, AstNode, BigIntLiteral, BooleanLiteral, BuildCodeFrameErrorFn, ConstValue, DecimalLiteral, ExpressionValue, FunctionValue, Identifier, ICSSRule, LazyValue, Location, NullLiteral, NumericLiteral, Replacement, Replacements, Rules, SourceLocation, StringLiteral, WYWEvalMeta, } from './types';
|
package/types/index.js
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, "hasEvalMeta", { enumerable: true, get: function () { return hasEvalMeta_1.hasEvalMeta; } });
|
|
11
|
-
var findPackageJSON_1 = require("./findPackageJSON");
|
|
12
|
-
Object.defineProperty(exports, "findPackageJSON", { enumerable: true, get: function () { return findPackageJSON_1.findPackageJSON; } });
|
|
13
|
-
var isBoxedPrimitive_1 = require("./isBoxedPrimitive");
|
|
14
|
-
Object.defineProperty(exports, "isBoxedPrimitive", { enumerable: true, get: function () { return isBoxedPrimitive_1.isBoxedPrimitive; } });
|
|
15
|
-
var logger_1 = require("./logger");
|
|
16
|
-
Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return logger_1.enableDebug; } });
|
|
17
|
-
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
18
|
-
var isFeatureEnabled_1 = require("./options/isFeatureEnabled");
|
|
19
|
-
Object.defineProperty(exports, "isFeatureEnabled", { enumerable: true, get: function () { return isFeatureEnabled_1.isFeatureEnabled; } });
|
|
20
|
-
var slugify_1 = require("./slugify");
|
|
21
|
-
Object.defineProperty(exports, "slugify", { enumerable: true, get: function () { return slugify_1.slugify; } });
|
|
22
|
-
var types_1 = require("./types");
|
|
23
|
-
Object.defineProperty(exports, "ValueType", { enumerable: true, get: function () { return types_1.ValueType; } });
|
|
1
|
+
export { asyncResolveFallback, syncResolve } from './asyncResolveFallback';
|
|
2
|
+
export { asyncResolverFactory } from './asyncResolverFactory';
|
|
3
|
+
export { hasEvalMeta } from './hasEvalMeta';
|
|
4
|
+
export { findPackageJSON } from './findPackageJSON';
|
|
5
|
+
export { isBoxedPrimitive } from './isBoxedPrimitive';
|
|
6
|
+
export { enableDebug, logger } from './logger';
|
|
7
|
+
export { isFeatureEnabled } from './options/isFeatureEnabled';
|
|
8
|
+
export { slugify } from './slugify';
|
|
9
|
+
export { ValueType } from './types';
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// There is a problem with using boxed numbers and strings in TS,
|
|
3
2
|
// so we cannot just use `instanceof` here
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.isBoxedPrimitive = isBoxedPrimitive;
|
|
6
3
|
const constructors = ['Number', 'String'];
|
|
7
|
-
function isBoxedPrimitive(o) {
|
|
4
|
+
export function isBoxedPrimitive(o) {
|
|
8
5
|
if (typeof o !== 'object' || o === null)
|
|
9
6
|
return false;
|
|
10
7
|
return (constructors.includes(o.constructor.name) &&
|
package/types/logger.js
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logger = void 0;
|
|
7
|
-
exports.enableDebug = enableDebug;
|
|
8
|
-
const debug_1 = __importDefault(require("debug"));
|
|
1
|
+
import genericDebug from 'debug';
|
|
9
2
|
const BASE_NAMESPACE = 'wyw-in-js';
|
|
10
|
-
|
|
3
|
+
export const logger = genericDebug(BASE_NAMESPACE);
|
|
11
4
|
const loggers = new Map();
|
|
12
5
|
function gerOrCreate(namespace) {
|
|
13
6
|
if (!namespace)
|
|
14
|
-
return
|
|
7
|
+
return logger;
|
|
15
8
|
const lastIndexOf = namespace.lastIndexOf(':');
|
|
16
9
|
if (!loggers.has(namespace)) {
|
|
17
10
|
loggers.set(namespace, gerOrCreate(namespace.substring(0, lastIndexOf)).extend(namespace.substring(lastIndexOf + 1)));
|
|
18
11
|
}
|
|
19
12
|
return loggers.get(namespace);
|
|
20
13
|
}
|
|
21
|
-
|
|
14
|
+
genericDebug.formatters.r = (ref) => {
|
|
22
15
|
const namespace = typeof ref === 'string' ? ref : ref.namespace;
|
|
23
16
|
const text = typeof ref === 'string' ? namespace : ref.text ?? namespace;
|
|
24
17
|
const color = parseInt(gerOrCreate(namespace).color, 10);
|
|
25
18
|
const colorCode = `\u001B[3${color < 8 ? color : `8;5;${color}`}`;
|
|
26
19
|
return `${colorCode};1m${text}\u001B[0m`;
|
|
27
20
|
};
|
|
28
|
-
|
|
21
|
+
genericDebug.formatters.f = function f(fn) {
|
|
29
22
|
return JSON.stringify(fn());
|
|
30
23
|
};
|
|
31
|
-
function enableDebug(namespace = `${BASE_NAMESPACE}:*`) {
|
|
32
|
-
|
|
24
|
+
export function enableDebug(namespace = `${BASE_NAMESPACE}:*`) {
|
|
25
|
+
genericDebug.enable(namespace);
|
|
33
26
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isFeatureEnabled = void 0;
|
|
4
|
-
const minimatch_1 = require("minimatch");
|
|
1
|
+
import { Minimatch } from 'minimatch';
|
|
5
2
|
const cachedMatchers = new Map();
|
|
6
|
-
const isFeatureEnabled = (features, featureName, filename) => {
|
|
3
|
+
export const isFeatureEnabled = (features, featureName, filename) => {
|
|
7
4
|
const value = features?.[featureName] ?? false;
|
|
8
5
|
if (typeof value === 'boolean') {
|
|
9
6
|
return value;
|
|
@@ -20,11 +17,10 @@ const isFeatureEnabled = (features, featureName, filename) => {
|
|
|
20
17
|
.map((pattern) => {
|
|
21
18
|
let matcher = cachedMatchers.get(pattern);
|
|
22
19
|
if (!matcher) {
|
|
23
|
-
matcher = [pattern.startsWith('!'), new
|
|
20
|
+
matcher = [pattern.startsWith('!'), new Minimatch(pattern)];
|
|
24
21
|
cachedMatchers.set(pattern, matcher);
|
|
25
22
|
}
|
|
26
23
|
return [matcher[0], matcher[1].match(filename)];
|
|
27
24
|
})
|
|
28
25
|
.reduce((acc, [negated, match]) => (negated ? acc && match : acc || match), false);
|
|
29
26
|
};
|
|
30
|
-
exports.isFeatureEnabled = isFeatureEnabled;
|
package/types/options/types.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type { TransformOptions } from '@babel/core';
|
|
2
|
-
import type { File } from '@babel/types';
|
|
3
1
|
import type { IVariableContext } from '../IVariableContext';
|
|
4
|
-
import type { Core } from '../babel';
|
|
5
2
|
type VmContext = Record<string, any>;
|
|
6
3
|
export type ClassNameSlugVars = {
|
|
7
4
|
dir: string;
|
|
@@ -21,15 +18,35 @@ export type EvaluatorConfig = {
|
|
|
21
18
|
onlyExports: string[];
|
|
22
19
|
root?: string;
|
|
23
20
|
};
|
|
24
|
-
export type
|
|
25
|
-
ast
|
|
21
|
+
export type EvaluatorOptions = {
|
|
22
|
+
ast?: boolean | null;
|
|
23
|
+
configFile?: boolean | null | string;
|
|
24
|
+
env?: Record<string, EvaluatorOptions | null | undefined> | null;
|
|
25
|
+
filename?: string | null;
|
|
26
|
+
inputSourceMap?: object | null;
|
|
27
|
+
overrides?: EvaluatorOptions[] | null;
|
|
28
|
+
plugins?: unknown[] | null;
|
|
29
|
+
presets?: unknown[] | null;
|
|
30
|
+
root?: string | null;
|
|
31
|
+
sourceFileName?: string | null;
|
|
32
|
+
sourceMaps?: boolean | 'both' | 'inline' | null;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
export type TransformEngineOptions = EvaluatorOptions;
|
|
36
|
+
export type EvaluatorAst = unknown;
|
|
37
|
+
export type EvaluatorRuntime = unknown;
|
|
38
|
+
export type Evaluator = (evalConfig: EvaluatorOptions, ast: EvaluatorAst, code: string, config: EvaluatorConfig, runtime: EvaluatorRuntime) => [
|
|
39
|
+
ast: EvaluatorAst,
|
|
26
40
|
code: string,
|
|
27
41
|
imports: Map<string, string[]> | null,
|
|
28
42
|
exports?: string[] | null
|
|
29
43
|
];
|
|
30
44
|
export type EvalRule = {
|
|
31
45
|
action: Evaluator | 'ignore' | string;
|
|
32
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Per-rule Oxc options for the Oxc-first transform path.
|
|
48
|
+
*/
|
|
49
|
+
oxcOptions?: OxcOptions;
|
|
33
50
|
test?: RegExp | ((path: string, code: string) => boolean);
|
|
34
51
|
};
|
|
35
52
|
export type FeatureFlag = boolean | string | string[];
|
|
@@ -76,6 +93,39 @@ export type ImportLoaderContext = {
|
|
|
76
93
|
};
|
|
77
94
|
export type ImportLoader = 'raw' | 'url' | ((context: ImportLoaderContext) => unknown);
|
|
78
95
|
export type ImportLoaders = Record<string, ImportLoader | false>;
|
|
96
|
+
export type EvalResolverMode = 'bundler' | 'hybrid' | 'node' | 'custom';
|
|
97
|
+
export type EvalRequireMode = 'warn-and-run' | 'error' | 'off';
|
|
98
|
+
export type EvalResolverKind = 'import' | 'dynamic-import' | 'require';
|
|
99
|
+
export type EvalWarningCode = 'resolve-fallback' | 'resolve-error' | 'require-fallback' | 'require-error' | 'dynamic-import' | 'eval-error';
|
|
100
|
+
export type EvalWarning = {
|
|
101
|
+
code: EvalWarningCode;
|
|
102
|
+
message: string;
|
|
103
|
+
importer?: string;
|
|
104
|
+
specifier?: string;
|
|
105
|
+
resolved?: string | null;
|
|
106
|
+
callstack?: string[];
|
|
107
|
+
hint?: string;
|
|
108
|
+
};
|
|
109
|
+
export type EvalOptionsV2 = {
|
|
110
|
+
/**
|
|
111
|
+
* Default is `bundler`. `hybrid` is an opt-in mode whose intended
|
|
112
|
+
* precedence is customResolver -> safe Oxc subset -> bundler -> node.
|
|
113
|
+
*/
|
|
114
|
+
resolver?: EvalResolverMode;
|
|
115
|
+
customResolver?: (specifier: string, importer: string, kind: EvalResolverKind) => Promise<{
|
|
116
|
+
id: string;
|
|
117
|
+
external?: boolean;
|
|
118
|
+
} | null>;
|
|
119
|
+
customLoader?: (id: string) => Promise<{
|
|
120
|
+
code: string;
|
|
121
|
+
map?: unknown;
|
|
122
|
+
loader?: string;
|
|
123
|
+
} | null>;
|
|
124
|
+
require?: EvalRequireMode;
|
|
125
|
+
mode?: 'strict' | 'loose';
|
|
126
|
+
globals?: Record<string, unknown>;
|
|
127
|
+
onWarn?: (warning: EvalWarning) => void;
|
|
128
|
+
};
|
|
79
129
|
export type TagResolverMeta = {
|
|
80
130
|
resolvedSource?: string;
|
|
81
131
|
sourceFile: string | null | undefined;
|
|
@@ -85,7 +135,7 @@ type AllFeatureFlags = {
|
|
|
85
135
|
globalCache: FeatureFlag;
|
|
86
136
|
happyDOM: FeatureFlag;
|
|
87
137
|
softErrors: FeatureFlag;
|
|
88
|
-
|
|
138
|
+
staticImportValues: FeatureFlag;
|
|
89
139
|
useWeakRefInEval: FeatureFlag;
|
|
90
140
|
};
|
|
91
141
|
export type FeatureFlags<TOnly extends keyof AllFeatureFlags = keyof AllFeatureFlags> = Pick<AllFeatureFlags, TOnly>;
|
|
@@ -93,13 +143,28 @@ export type CodeRemoverOptions = {
|
|
|
93
143
|
componentTypes?: Record<string, string[]>;
|
|
94
144
|
hocs?: Record<string, string[]>;
|
|
95
145
|
};
|
|
146
|
+
export type OxcOptions = {
|
|
147
|
+
/**
|
|
148
|
+
* Parser-level Oxc options. The first slice only preserves this contract.
|
|
149
|
+
*/
|
|
150
|
+
parser?: Record<string, unknown>;
|
|
151
|
+
/**
|
|
152
|
+
* Resolver-level Oxc options. Bundler-aware resolution remains authoritative
|
|
153
|
+
* unless `eval.resolver` explicitly opts into `hybrid`.
|
|
154
|
+
*/
|
|
155
|
+
resolver?: Record<string, unknown>;
|
|
156
|
+
/**
|
|
157
|
+
* Transform-level Oxc options.
|
|
158
|
+
*/
|
|
159
|
+
transform?: Record<string, unknown>;
|
|
160
|
+
};
|
|
96
161
|
export type StrictOptions = {
|
|
97
|
-
babelOptions: TransformOptions;
|
|
98
162
|
classNameSlug?: string | ClassNameFn;
|
|
99
163
|
codeRemover?: CodeRemoverOptions;
|
|
100
164
|
conditionNames?: string[];
|
|
101
165
|
displayName: boolean;
|
|
102
166
|
evaluate: boolean;
|
|
167
|
+
eval?: EvalOptionsV2;
|
|
103
168
|
extensions: string[];
|
|
104
169
|
features: FeatureFlags;
|
|
105
170
|
highPriorityPlugins: string[];
|
|
@@ -108,8 +173,13 @@ export type StrictOptions = {
|
|
|
108
173
|
importOverrides?: ImportOverrides;
|
|
109
174
|
outputMetadata: boolean;
|
|
110
175
|
overrideContext?: (context: Partial<VmContext>, filename: string) => Partial<VmContext>;
|
|
176
|
+
/**
|
|
177
|
+
* Oxc-first transform options.
|
|
178
|
+
*/
|
|
179
|
+
oxcOptions: OxcOptions;
|
|
111
180
|
rules: EvalRule[];
|
|
112
181
|
tagResolver?: (source: string, tag: string, meta: TagResolverMeta) => string | null;
|
|
182
|
+
evalConsole?: 'warning' | 'pipe';
|
|
113
183
|
variableNameConfig?: 'var' | 'dashes' | 'raw';
|
|
114
184
|
variableNameSlug?: string | VariableNameFn;
|
|
115
185
|
};
|
package/types/options/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/types/slugify.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable no-plusplus, no-bitwise, default-case, no-param-reassign, prefer-destructuring */
|
|
3
2
|
/**
|
|
4
3
|
* This file contains a utility to generate hashes to be used as generated class names
|
|
5
4
|
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.slugify = slugify;
|
|
8
5
|
/**
|
|
9
6
|
* murmurhash2 via https://gist.github.com/raycmorgan/588423
|
|
10
7
|
*/
|
|
@@ -60,6 +57,6 @@ function doHash(str, seed = 0) {
|
|
|
60
57
|
h ^= h >>> 15;
|
|
61
58
|
return h >>> 0;
|
|
62
59
|
}
|
|
63
|
-
function slugify(code) {
|
|
60
|
+
export function slugify(code) {
|
|
64
61
|
return doHash(code).toString(36);
|
|
65
62
|
}
|