@wyw-in-js/esbuild 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/README.md +12 -13
- package/esm/index.mjs +206 -233
- package/esm/index.mjs.map +1 -1
- package/package.json +13 -13
- package/types/index.d.ts +2 -2
- package/types/index.js +62 -57
- package/lib/index.js +0 -243
- package/lib/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -34,28 +34,27 @@ esbuild
|
|
|
34
34
|
.catch(() => process.exit(1));
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
## Additional
|
|
37
|
+
## Additional Oxc transformations
|
|
38
38
|
|
|
39
|
-
`@wyw-in-js/esbuild` runs WyW evaluation after an `esbuild.transform()` step, so
|
|
40
|
-
|
|
39
|
+
`@wyw-in-js/esbuild` runs WyW evaluation after an `esbuild.transform()` step, so transform options that must run on the
|
|
40
|
+
original TS/JSX source should be configured explicitly.
|
|
41
41
|
|
|
42
|
-
Enable `
|
|
42
|
+
Enable `oxcTransform` to apply `oxcOptions.transform` to the original source code before the esbuild/WyW pipeline:
|
|
43
43
|
|
|
44
44
|
```js
|
|
45
45
|
wyw({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
oxcTransform: true,
|
|
47
|
+
oxcOptions: {
|
|
48
|
+
transform: {
|
|
49
|
+
define: {
|
|
50
|
+
__DEV__: 'false',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
51
53
|
},
|
|
52
54
|
});
|
|
53
55
|
```
|
|
54
56
|
|
|
55
|
-
Order: `
|
|
56
|
-
|
|
57
|
-
Note: `babelOptions` are still used by WyW when parsing/evaluating modules. With `babelTransform: true`, the same plugins
|
|
58
|
-
may run both before esbuild and again during WyW's internal Babel stage. Prefer idempotent plugins.
|
|
57
|
+
Order: `Oxc(source) → esbuild.transform() → WyW transform`.
|
|
59
58
|
|
|
60
59
|
This is an opt-in feature and may increase build times, so it's recommended to keep `filter` narrow.
|
|
61
60
|
|
package/esm/index.mjs
CHANGED
|
@@ -1,236 +1,209 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { transformSync as
|
|
10
|
-
import { slugify, transform, TransformCacheCollection, createFileReporter, loadWywOptions
|
|
11
|
-
import { asyncResolverFactory } from
|
|
12
|
-
const supportedFilterFlags = new Set([
|
|
2
|
+
* This file contains an esbuild loader for wyw-in-js.
|
|
3
|
+
* It uses the transform.ts function to generate class names from source code,
|
|
4
|
+
* returns transformed code without template literals and attaches generated source maps
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync } from "fs";
|
|
7
|
+
import { dirname, isAbsolute, join, parse, posix } from "path";
|
|
8
|
+
import { transformSync as esbuildTransformSync } from "esbuild";
|
|
9
|
+
import { transformSync as oxcTransformSync } from "oxc-transform";
|
|
10
|
+
import { disposeEvalBroker, slugify, transform, TransformCacheCollection, createFileReporter, loadWywOptions } from "@wyw-in-js/transform";
|
|
11
|
+
import { asyncResolverFactory } from "@wyw-in-js/shared";
|
|
12
|
+
const supportedFilterFlags = new Set([
|
|
13
|
+
"i",
|
|
14
|
+
"m",
|
|
15
|
+
"s"
|
|
16
|
+
]);
|
|
13
17
|
const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
|
|
14
|
-
export default function wywInJS({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
205
|
-
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
|
|
206
|
-
}
|
|
207
|
-
return {
|
|
208
|
-
contents,
|
|
209
|
-
loader,
|
|
210
|
-
resolveDir
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
let {
|
|
214
|
-
cssText
|
|
215
|
-
} = result;
|
|
216
|
-
const slug = slugify(cssText);
|
|
217
|
-
const cssFilename = `${filename}_${slug}.wyw.css`;
|
|
218
|
-
let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;
|
|
219
|
-
if (sourceMap && result.cssSourceMapText) {
|
|
220
|
-
const map = Buffer.from(result.cssSourceMapText).toString('base64');
|
|
221
|
-
cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
|
|
222
|
-
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
223
|
-
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
|
|
224
|
-
}
|
|
225
|
-
cssLookup.set(cssFilename, cssText);
|
|
226
|
-
cssResolveDirs.set(cssFilename, resolveDir);
|
|
227
|
-
return {
|
|
228
|
-
contents,
|
|
229
|
-
loader,
|
|
230
|
-
resolveDir
|
|
231
|
-
};
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
};
|
|
18
|
+
export default function wywInJS({ debug, sourceMap, keepComments, oxcTransform, prefixer, preprocessor, esbuildOptions, filter = /\.(js|jsx|ts|tsx)$/, transformLibraries, ...rest } = {}) {
|
|
19
|
+
let options = esbuildOptions;
|
|
20
|
+
const cache = new TransformCacheCollection();
|
|
21
|
+
const shouldRunOxcTransform = oxcTransform ?? false;
|
|
22
|
+
const resolvedWywOptions = shouldRunOxcTransform ? loadWywOptions(rest) : null;
|
|
23
|
+
const createAsyncResolver = asyncResolverFactory(async (resolved, token) => {
|
|
24
|
+
if (resolved.errors.length > 0) {
|
|
25
|
+
throw new Error(`Cannot resolve ${token}`);
|
|
26
|
+
}
|
|
27
|
+
return resolved.path.replace(/\\/g, posix.sep);
|
|
28
|
+
}, (what, importer) => [what, {
|
|
29
|
+
resolveDir: isAbsolute(importer) ? dirname(importer) : join(process.cwd(), dirname(importer)),
|
|
30
|
+
kind: "import-statement"
|
|
31
|
+
}]);
|
|
32
|
+
return {
|
|
33
|
+
name: "wyw-in-js",
|
|
34
|
+
setup(build) {
|
|
35
|
+
const cssLookup = new Map();
|
|
36
|
+
const cssResolveDirs = new Map();
|
|
37
|
+
const warnedFilters = new Set();
|
|
38
|
+
let warnedEmptyOxcOptions = false;
|
|
39
|
+
const { emitter, onDone } = createFileReporter(debug ?? false);
|
|
40
|
+
const warnOnUnsupportedFlags = (filterRegexp, removedFlags, sanitizedFlags) => {
|
|
41
|
+
const key = `${filterRegexp.source}/${filterRegexp.flags}`;
|
|
42
|
+
if (warnedFilters.has(key)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
warnedFilters.add(key);
|
|
46
|
+
const nextFlags = sanitizedFlags || "none";
|
|
47
|
+
// eslint-disable-next-line no-console
|
|
48
|
+
console.warn(`[wyw-in-js] Ignoring unsupported RegExp flags "${removedFlags}" ` + `in esbuild filter /${filterRegexp.source}/${filterRegexp.flags}. ` + `Using flags "${nextFlags}".`);
|
|
49
|
+
};
|
|
50
|
+
const sanitizeFilter = (filterRegexp) => {
|
|
51
|
+
const { flags } = filterRegexp;
|
|
52
|
+
const sanitizedFlags = flags.split("").filter((flag) => supportedFilterFlags.has(flag)).join("");
|
|
53
|
+
if (sanitizedFlags === flags) {
|
|
54
|
+
return filterRegexp;
|
|
55
|
+
}
|
|
56
|
+
const removedFlags = flags.split("").filter((flag) => !supportedFilterFlags.has(flag)).join("");
|
|
57
|
+
warnOnUnsupportedFlags(filterRegexp, removedFlags, sanitizedFlags);
|
|
58
|
+
return new RegExp(filterRegexp.source, sanitizedFlags);
|
|
59
|
+
};
|
|
60
|
+
const getOxcLang = (loader) => {
|
|
61
|
+
if (loader === "tsx") return "tsx";
|
|
62
|
+
if (loader === "ts") return "ts";
|
|
63
|
+
if (loader === "jsx") return "jsx";
|
|
64
|
+
return "js";
|
|
65
|
+
};
|
|
66
|
+
const asyncResolve = createAsyncResolver(build.resolve);
|
|
67
|
+
build.onEnd(() => {
|
|
68
|
+
onDone(process.cwd());
|
|
69
|
+
disposeEvalBroker(cache);
|
|
70
|
+
});
|
|
71
|
+
build.onResolve({ filter: /\.wyw\.css$/ }, (args) => {
|
|
72
|
+
return {
|
|
73
|
+
namespace: "wyw-in-js",
|
|
74
|
+
path: args.path
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
build.onLoad({
|
|
78
|
+
filter: /.*/,
|
|
79
|
+
namespace: "wyw-in-js"
|
|
80
|
+
}, (args) => {
|
|
81
|
+
return {
|
|
82
|
+
contents: cssLookup.get(args.path),
|
|
83
|
+
loader: "css",
|
|
84
|
+
resolveDir: cssResolveDirs.get(args.path)
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
const filterRegexp = typeof filter === "string" ? new RegExp(filter) : sanitizeFilter(filter);
|
|
88
|
+
build.onLoad({ filter: filterRegexp }, async (args) => {
|
|
89
|
+
const rawCode = readFileSync(args.path, "utf8");
|
|
90
|
+
const { ext, name: filename } = parse(args.path);
|
|
91
|
+
const loader = ext.replace(/^\./, "");
|
|
92
|
+
if (!transformLibraries && nodeModulesRegex.test(args.path)) {
|
|
93
|
+
return {
|
|
94
|
+
loader,
|
|
95
|
+
contents: rawCode
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (!options) {
|
|
99
|
+
options = {};
|
|
100
|
+
if ("jsxFactory" in build.initialOptions) {
|
|
101
|
+
options.jsxFactory = build.initialOptions.jsxFactory;
|
|
102
|
+
}
|
|
103
|
+
if ("jsxFragment" in build.initialOptions) {
|
|
104
|
+
options.jsxFragment = build.initialOptions.jsxFragment;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let codeForEsbuild = rawCode;
|
|
108
|
+
if (shouldRunOxcTransform) {
|
|
109
|
+
if (!resolvedWywOptions) {
|
|
110
|
+
throw new Error("[wyw-in-js] Internal error: oxcTransform is enabled but WyW options are not initialized");
|
|
111
|
+
}
|
|
112
|
+
const transformOptions = resolvedWywOptions.oxcOptions.transform;
|
|
113
|
+
if (!transformOptions || !Object.keys(transformOptions).length) {
|
|
114
|
+
if (!warnedEmptyOxcOptions) {
|
|
115
|
+
warnedEmptyOxcOptions = true;
|
|
116
|
+
// eslint-disable-next-line no-console
|
|
117
|
+
console.warn("[wyw-in-js] oxcTransform is enabled but oxcOptions.transform is empty; skipping Oxc transform.");
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
let oxcResult;
|
|
121
|
+
try {
|
|
122
|
+
oxcResult = oxcTransformSync(args.path, codeForEsbuild, {
|
|
123
|
+
cwd: process.cwd(),
|
|
124
|
+
lang: getOxcLang(loader),
|
|
125
|
+
sourceType: "module",
|
|
126
|
+
sourcemap: sourceMap,
|
|
127
|
+
...transformOptions
|
|
128
|
+
});
|
|
129
|
+
} catch (e) {
|
|
130
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
131
|
+
throw new Error(`[wyw-in-js] Oxc transform failed for ${args.path}: ${message}`);
|
|
132
|
+
}
|
|
133
|
+
if (oxcResult.errors.length > 0) {
|
|
134
|
+
const details = oxcResult.errors.map((error) => error.codeframe ? `${error.message}\n${error.codeframe}` : error.message).join("\n");
|
|
135
|
+
throw new Error(`[wyw-in-js] Oxc transform failed for ${args.path}: ${details}`);
|
|
136
|
+
}
|
|
137
|
+
codeForEsbuild = oxcResult.code;
|
|
138
|
+
if (sourceMap && oxcResult.map) {
|
|
139
|
+
const oxcMap = Buffer.from(JSON.stringify(oxcResult.map)).toString("base64");
|
|
140
|
+
codeForEsbuild += `/*# sourceMappingURL=data:application/json;base64,${oxcMap}*/`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const transformed = esbuildTransformSync(codeForEsbuild, {
|
|
145
|
+
...options,
|
|
146
|
+
sourcefile: args.path,
|
|
147
|
+
sourcemap: sourceMap,
|
|
148
|
+
loader
|
|
149
|
+
});
|
|
150
|
+
let { code } = transformed;
|
|
151
|
+
if (sourceMap) {
|
|
152
|
+
const esbuildMap = Buffer.from(transformed.map).toString("base64");
|
|
153
|
+
code += `/*# sourceMappingURL=data:application/json;base64,${esbuildMap}*/`;
|
|
154
|
+
}
|
|
155
|
+
const transformServices = {
|
|
156
|
+
options: {
|
|
157
|
+
filename: args.path,
|
|
158
|
+
pluginOptions: rest,
|
|
159
|
+
prefixer,
|
|
160
|
+
keepComments,
|
|
161
|
+
preprocessor,
|
|
162
|
+
root: process.cwd()
|
|
163
|
+
},
|
|
164
|
+
cache,
|
|
165
|
+
eventEmitter: emitter
|
|
166
|
+
};
|
|
167
|
+
const result = await transform(transformServices, code, asyncResolve);
|
|
168
|
+
const resolveDir = dirname(args.path);
|
|
169
|
+
if (typeof result.cssText === "undefined") {
|
|
170
|
+
return {
|
|
171
|
+
contents: code,
|
|
172
|
+
loader,
|
|
173
|
+
resolveDir
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (result.cssText === "") {
|
|
177
|
+
let contents = result.code;
|
|
178
|
+
if (sourceMap && result.sourceMap) {
|
|
179
|
+
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString("base64");
|
|
180
|
+
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
contents,
|
|
184
|
+
loader,
|
|
185
|
+
resolveDir
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
let { cssText } = result;
|
|
189
|
+
const slug = slugify(cssText);
|
|
190
|
+
const cssFilename = `${filename}_${slug}.wyw.css`;
|
|
191
|
+
let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;
|
|
192
|
+
if (sourceMap && result.cssSourceMapText) {
|
|
193
|
+
const map = Buffer.from(result.cssSourceMapText).toString("base64");
|
|
194
|
+
cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
|
|
195
|
+
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString("base64");
|
|
196
|
+
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
|
|
197
|
+
}
|
|
198
|
+
cssLookup.set(cssFilename, cssText);
|
|
199
|
+
cssResolveDirs.set(cssFilename, resolveDir);
|
|
200
|
+
return {
|
|
201
|
+
contents,
|
|
202
|
+
loader,
|
|
203
|
+
resolveDir
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
};
|
|
235
208
|
}
|
|
236
|
-
//# sourceMappingURL=index.mjs.map
|
|
209
|
+
//# sourceMappingURL=index.mjs.map
|
package/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["readFileSync","dirname","isAbsolute","join","parse","posix","transformSync","esbuildTransformSync","slugify","transform","TransformCacheCollection","createFileReporter","loadWywOptions","withDefaultServices","asyncResolverFactory","supportedFilterFlags","Set","nodeModulesRegex","wywInJS","babelTransform","debug","sourceMap","keepComments","prefixer","preprocessor","esbuildOptions","filter","transformLibraries","rest","options","cache","resolvedWywOptions","babel","filename","pluginOptions","root","process","cwd","createAsyncResolver","resolved","token","errors","length","Error","path","replace","sep","what","importer","resolveDir","kind","name","setup","build","cssLookup","Map","cssResolveDirs","warnedFilters","warnedEmptyBabelOptions","emitter","onDone","warnOnUnsupportedFlags","filterRegexp","removedFlags","sanitizedFlags","key","source","flags","has","add","nextFlags","console","warn","sanitizeFilter","split","flag","RegExp","asyncResolve","resolve","onEnd","onResolve","args","namespace","onLoad","contents","get","loader","rawCode","ext","test","initialOptions","jsxFactory","jsxFragment","codeForEsbuild","babelOptions","Object","keys","babelResult","ast","sourceFileName","sourceMaps","e","message","String","code","map","babelMap","Buffer","from","JSON","stringify","toString","transformed","sourcefile","sourcemap","esbuildMap","transformServices","eventEmitter","result","cssText","wywMap","slug","cssFilename","cssSourceMapText","set"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * This file contains an esbuild loader for wyw-in-js.\n * It uses the transform.ts function to generate class names from source code,\n * returns transformed code without template literals and attaches generated source maps\n */\n\nimport { readFileSync } from 'fs';\nimport { dirname, isAbsolute, join, parse, posix } from 'path';\n\nimport type { Plugin, TransformOptions, Loader } from 'esbuild';\nimport { transformSync as esbuildTransformSync } from 'esbuild';\n\nimport type {\n PluginOptions,\n Preprocessor,\n IFileReporterOptions,\n} from '@wyw-in-js/transform';\nimport {\n slugify,\n transform,\n TransformCacheCollection,\n createFileReporter,\n loadWywOptions,\n withDefaultServices,\n} from '@wyw-in-js/transform';\nimport { asyncResolverFactory } from '@wyw-in-js/shared';\n\ntype EsbuildPluginOptions = {\n babelTransform?: boolean;\n debug?: IFileReporterOptions | false | null | undefined;\n esbuildOptions?: TransformOptions;\n filter?: RegExp | string;\n keepComments?: boolean | RegExp;\n prefixer?: boolean;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n transformLibraries?: boolean;\n} & Partial<PluginOptions>;\n\nconst supportedFilterFlags = new Set(['i', 'm', 's']);\n\nconst nodeModulesRegex = /^(?:.*[\\\\/])?node_modules(?:[\\\\/].*)?$/;\n\nexport default function wywInJS({\n babelTransform,\n debug,\n sourceMap,\n keepComments,\n prefixer,\n preprocessor,\n esbuildOptions,\n filter = /\\.(js|jsx|ts|tsx)$/,\n transformLibraries,\n ...rest\n}: EsbuildPluginOptions = {}): Plugin {\n let options = esbuildOptions;\n const cache = new TransformCacheCollection();\n let resolvedWywOptions: ReturnType<typeof loadWywOptions> | null = null;\n let babel: ReturnType<typeof withDefaultServices>['babel'] | null = null;\n if (babelTransform) {\n resolvedWywOptions = loadWywOptions(rest);\n babel = withDefaultServices({\n options: {\n filename: '<wyw-in-js/esbuild>',\n pluginOptions: resolvedWywOptions,\n root: process.cwd(),\n },\n }).babel;\n }\n const createAsyncResolver = asyncResolverFactory(\n async (\n resolved: {\n errors: unknown[];\n path: string;\n },\n token: string\n ): Promise<string> => {\n if (resolved.errors.length > 0) {\n throw new Error(`Cannot resolve ${token}`);\n }\n\n return resolved.path.replace(/\\\\/g, posix.sep);\n },\n (what, importer) => [\n what,\n {\n resolveDir: isAbsolute(importer)\n ? dirname(importer)\n : join(process.cwd(), dirname(importer)),\n kind: 'import-statement',\n },\n ]\n );\n return {\n name: 'wyw-in-js',\n setup(build) {\n const cssLookup = new Map<string, string>();\n const cssResolveDirs = new Map<string, string>();\n const warnedFilters = new Set<string>();\n let warnedEmptyBabelOptions = false;\n\n const { emitter, onDone } = createFileReporter(debug ?? false);\n\n const warnOnUnsupportedFlags = (\n filterRegexp: RegExp,\n removedFlags: string,\n sanitizedFlags: string\n ) => {\n const key = `${filterRegexp.source}/${filterRegexp.flags}`;\n if (warnedFilters.has(key)) {\n return;\n }\n warnedFilters.add(key);\n const nextFlags = sanitizedFlags || 'none';\n // eslint-disable-next-line no-console\n console.warn(\n `[wyw-in-js] Ignoring unsupported RegExp flags \"${removedFlags}\" ` +\n `in esbuild filter /${filterRegexp.source}/${filterRegexp.flags}. ` +\n `Using flags \"${nextFlags}\".`\n );\n };\n\n const sanitizeFilter = (filterRegexp: RegExp): RegExp => {\n const { flags } = filterRegexp;\n const sanitizedFlags = flags\n .split('')\n .filter((flag) => supportedFilterFlags.has(flag))\n .join('');\n if (sanitizedFlags === flags) {\n return filterRegexp;\n }\n const removedFlags = flags\n .split('')\n .filter((flag) => !supportedFilterFlags.has(flag))\n .join('');\n warnOnUnsupportedFlags(filterRegexp, removedFlags, sanitizedFlags);\n return new RegExp(filterRegexp.source, sanitizedFlags);\n };\n\n const asyncResolve = createAsyncResolver(build.resolve);\n\n build.onEnd(() => {\n onDone(process.cwd());\n });\n\n build.onResolve({ filter: /\\.wyw\\.css$/ }, (args) => {\n return {\n namespace: 'wyw-in-js',\n path: args.path,\n };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, (args) => {\n return {\n contents: cssLookup.get(args.path),\n loader: 'css',\n resolveDir: cssResolveDirs.get(args.path),\n };\n });\n\n const filterRegexp =\n typeof filter === 'string'\n ? new RegExp(filter)\n : sanitizeFilter(filter);\n\n build.onLoad({ filter: filterRegexp }, async (args) => {\n const rawCode = readFileSync(args.path, 'utf8');\n const { ext, name: filename } = parse(args.path);\n const loader = ext.replace(/^\\./, '') as Loader;\n\n if (!transformLibraries && nodeModulesRegex.test(args.path)) {\n return {\n loader,\n contents: rawCode,\n };\n }\n\n if (!options) {\n options = {};\n if ('jsxFactory' in build.initialOptions) {\n options.jsxFactory = build.initialOptions.jsxFactory;\n }\n if ('jsxFragment' in build.initialOptions) {\n options.jsxFragment = build.initialOptions.jsxFragment;\n }\n }\n\n let codeForEsbuild = rawCode;\n if (babelTransform) {\n if (!babel || !resolvedWywOptions) {\n throw new Error(\n '[wyw-in-js] Internal error: babelTransform is enabled but Babel services are not initialized'\n );\n }\n\n const { babelOptions } = resolvedWywOptions;\n if (!Object.keys(babelOptions).length) {\n if (!warnedEmptyBabelOptions) {\n warnedEmptyBabelOptions = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[wyw-in-js] babelTransform is enabled but babelOptions is empty; skipping Babel transform.'\n );\n }\n } else {\n let babelResult;\n try {\n babelResult = babel.transformSync(codeForEsbuild, {\n ...babelOptions,\n ast: false,\n filename: args.path,\n sourceFileName: args.path,\n sourceMaps: sourceMap,\n });\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n throw new Error(\n `[wyw-in-js] Babel transform failed for ${args.path}: ${message}`\n );\n }\n\n if (!babelResult?.code) {\n throw new Error(\n `[wyw-in-js] Babel transform failed for ${args.path}`\n );\n }\n\n codeForEsbuild = babelResult.code;\n\n if (sourceMap && babelResult.map) {\n const babelMap = Buffer.from(\n JSON.stringify(babelResult.map)\n ).toString('base64');\n codeForEsbuild += `/*# sourceMappingURL=data:application/json;base64,${babelMap}*/`;\n }\n }\n }\n\n const transformed = esbuildTransformSync(codeForEsbuild, {\n ...options,\n sourcefile: args.path,\n sourcemap: sourceMap,\n loader,\n });\n let { code } = transformed;\n\n if (sourceMap) {\n const esbuildMap = Buffer.from(transformed.map).toString('base64');\n code += `/*# sourceMappingURL=data:application/json;base64,${esbuildMap}*/`;\n }\n\n const transformServices = {\n options: {\n filename: args.path,\n pluginOptions: rest,\n prefixer,\n keepComments,\n preprocessor,\n root: process.cwd(),\n },\n cache,\n eventEmitter: emitter,\n };\n\n const result = await transform(transformServices, code, asyncResolve);\n const resolveDir = dirname(args.path);\n\n if (typeof result.cssText === 'undefined') {\n return {\n contents: code,\n loader,\n resolveDir,\n };\n }\n\n if (result.cssText === '') {\n let contents = result.code;\n\n if (sourceMap && result.sourceMap) {\n const wywMap = Buffer.from(\n JSON.stringify(result.sourceMap)\n ).toString('base64');\n contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;\n }\n\n return {\n contents,\n loader,\n resolveDir,\n };\n }\n\n let { cssText } = result;\n\n const slug = slugify(cssText);\n const cssFilename = `${filename}_${slug}.wyw.css`;\n\n let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;\n\n if (sourceMap && result.cssSourceMapText) {\n const map = Buffer.from(result.cssSourceMapText).toString('base64');\n cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;\n const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;\n }\n\n cssLookup.set(cssFilename, cssText);\n cssResolveDirs.set(cssFilename, resolveDir);\n\n return {\n contents,\n loader,\n resolveDir,\n };\n });\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,QAAQ,IAAI;AACjC,SAASC,OAAO,EAAEC,UAAU,EAAEC,IAAI,EAAEC,KAAK,EAAEC,KAAK,QAAQ,MAAM;AAG9D,SAASC,aAAa,IAAIC,oBAAoB,QAAQ,SAAS;AAO/D,SACEC,OAAO,EACPC,SAAS,EACTC,wBAAwB,EACxBC,kBAAkB,EAClBC,cAAc,EACdC,mBAAmB,QACd,sBAAsB;AAC7B,SAASC,oBAAoB,QAAQ,mBAAmB;AAcxD,MAAMC,oBAAoB,GAAG,IAAIC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAErD,MAAMC,gBAAgB,GAAG,wCAAwC;AAEjE,eAAe,SAASC,OAAOA,CAAC;EAC9BC,cAAc;EACdC,KAAK;EACLC,SAAS;EACTC,YAAY;EACZC,QAAQ;EACRC,YAAY;EACZC,cAAc;EACdC,MAAM,GAAG,oBAAoB;EAC7BC,kBAAkB;EAClB,GAAGC;AACiB,CAAC,G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G,KAAK;IAExC,IAAI,WAAW,UAAU,KAAK,UAAU,YAAY,CAAC,IAAI,OAAO;AAEhE,QAAI,aAAa,OAAO,kBAAkB;KACxC,MAAM,MAAM,OAAO,KAAK,OAAO,iBAAiB,CAAC,SAAS,SAAS;AACnE,gBAAW,qDAAqD,IAAI;KACpE,MAAM,SAAS,OAAO,KAAK,KAAK,UAAU,OAAO,UAAU,CAAC,CAAC,SAC3D,SACD;AACD,iBAAY,qDAAqD,OAAO;;AAG1E,cAAU,IAAI,aAAa,QAAQ;AACnC,mBAAe,IAAI,aAAa,WAAW;AAE3C,WAAO;KACL;KACA;KACA;KACD;KACD;;EAEL","names":[],"sources":["../src/index.ts"],"version":3,"sourcesContent":["/**\n * This file contains an esbuild loader for wyw-in-js.\n * It uses the transform.ts function to generate class names from source code,\n * returns transformed code without template literals and attaches generated source maps\n */\n\nimport { readFileSync } from 'fs';\nimport { dirname, isAbsolute, join, parse, posix } from 'path';\n\nimport type { Plugin, TransformOptions, Loader } from 'esbuild';\nimport { transformSync as esbuildTransformSync } from 'esbuild';\nimport {\n transformSync as oxcTransformSync,\n type TransformOptions as OxcTransformOptions,\n} from 'oxc-transform';\n\nimport type {\n PluginOptions,\n Preprocessor,\n IFileReporterOptions,\n} from '@wyw-in-js/transform';\nimport {\n disposeEvalBroker,\n slugify,\n transform,\n TransformCacheCollection,\n createFileReporter,\n loadWywOptions,\n} from '@wyw-in-js/transform';\nimport { asyncResolverFactory } from '@wyw-in-js/shared';\n\ntype EsbuildPluginOptions = {\n debug?: IFileReporterOptions | false | null | undefined;\n esbuildOptions?: TransformOptions;\n filter?: RegExp | string;\n keepComments?: boolean | RegExp;\n oxcTransform?: boolean;\n prefixer?: boolean;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n transformLibraries?: boolean;\n} & Partial<PluginOptions>;\n\nconst supportedFilterFlags = new Set(['i', 'm', 's']);\n\nconst nodeModulesRegex = /^(?:.*[\\\\/])?node_modules(?:[\\\\/].*)?$/;\n\nexport default function wywInJS({\n debug,\n sourceMap,\n keepComments,\n oxcTransform,\n prefixer,\n preprocessor,\n esbuildOptions,\n filter = /\\.(js|jsx|ts|tsx)$/,\n transformLibraries,\n ...rest\n}: EsbuildPluginOptions = {}): Plugin {\n let options = esbuildOptions;\n const cache = new TransformCacheCollection();\n const shouldRunOxcTransform = oxcTransform ?? false;\n const resolvedWywOptions = shouldRunOxcTransform\n ? loadWywOptions(rest)\n : null;\n const createAsyncResolver = asyncResolverFactory(\n async (\n resolved: {\n errors: unknown[];\n path: string;\n },\n token: string\n ): Promise<string> => {\n if (resolved.errors.length > 0) {\n throw new Error(`Cannot resolve ${token}`);\n }\n\n return resolved.path.replace(/\\\\/g, posix.sep);\n },\n (what, importer) => [\n what,\n {\n resolveDir: isAbsolute(importer)\n ? dirname(importer)\n : join(process.cwd(), dirname(importer)),\n kind: 'import-statement',\n },\n ]\n );\n return {\n name: 'wyw-in-js',\n setup(build) {\n const cssLookup = new Map<string, string>();\n const cssResolveDirs = new Map<string, string>();\n const warnedFilters = new Set<string>();\n let warnedEmptyOxcOptions = false;\n\n const { emitter, onDone } = createFileReporter(debug ?? false);\n\n const warnOnUnsupportedFlags = (\n filterRegexp: RegExp,\n removedFlags: string,\n sanitizedFlags: string\n ) => {\n const key = `${filterRegexp.source}/${filterRegexp.flags}`;\n if (warnedFilters.has(key)) {\n return;\n }\n warnedFilters.add(key);\n const nextFlags = sanitizedFlags || 'none';\n // eslint-disable-next-line no-console\n console.warn(\n `[wyw-in-js] Ignoring unsupported RegExp flags \"${removedFlags}\" ` +\n `in esbuild filter /${filterRegexp.source}/${filterRegexp.flags}. ` +\n `Using flags \"${nextFlags}\".`\n );\n };\n\n const sanitizeFilter = (filterRegexp: RegExp): RegExp => {\n const { flags } = filterRegexp;\n const sanitizedFlags = flags\n .split('')\n .filter((flag) => supportedFilterFlags.has(flag))\n .join('');\n if (sanitizedFlags === flags) {\n return filterRegexp;\n }\n const removedFlags = flags\n .split('')\n .filter((flag) => !supportedFilterFlags.has(flag))\n .join('');\n warnOnUnsupportedFlags(filterRegexp, removedFlags, sanitizedFlags);\n return new RegExp(filterRegexp.source, sanitizedFlags);\n };\n\n const getOxcLang = (loader: Loader): OxcTransformOptions['lang'] => {\n if (loader === 'tsx') return 'tsx';\n if (loader === 'ts') return 'ts';\n if (loader === 'jsx') return 'jsx';\n return 'js';\n };\n\n const asyncResolve = createAsyncResolver(build.resolve);\n\n build.onEnd(() => {\n onDone(process.cwd());\n disposeEvalBroker(cache);\n });\n\n build.onResolve({ filter: /\\.wyw\\.css$/ }, (args) => {\n return {\n namespace: 'wyw-in-js',\n path: args.path,\n };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, (args) => {\n return {\n contents: cssLookup.get(args.path),\n loader: 'css',\n resolveDir: cssResolveDirs.get(args.path),\n };\n });\n\n const filterRegexp =\n typeof filter === 'string'\n ? new RegExp(filter)\n : sanitizeFilter(filter);\n\n build.onLoad({ filter: filterRegexp }, async (args) => {\n const rawCode = readFileSync(args.path, 'utf8');\n const { ext, name: filename } = parse(args.path);\n const loader = ext.replace(/^\\./, '') as Loader;\n\n if (!transformLibraries && nodeModulesRegex.test(args.path)) {\n return {\n loader,\n contents: rawCode,\n };\n }\n\n if (!options) {\n options = {};\n if ('jsxFactory' in build.initialOptions) {\n options.jsxFactory = build.initialOptions.jsxFactory;\n }\n if ('jsxFragment' in build.initialOptions) {\n options.jsxFragment = build.initialOptions.jsxFragment;\n }\n }\n\n let codeForEsbuild = rawCode;\n if (shouldRunOxcTransform) {\n if (!resolvedWywOptions) {\n throw new Error(\n '[wyw-in-js] Internal error: oxcTransform is enabled but WyW options are not initialized'\n );\n }\n\n const transformOptions = resolvedWywOptions.oxcOptions.transform as\n | OxcTransformOptions\n | undefined;\n if (!transformOptions || !Object.keys(transformOptions).length) {\n if (!warnedEmptyOxcOptions) {\n warnedEmptyOxcOptions = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[wyw-in-js] oxcTransform is enabled but oxcOptions.transform is empty; skipping Oxc transform.'\n );\n }\n } else {\n let oxcResult;\n try {\n oxcResult = oxcTransformSync(args.path, codeForEsbuild, {\n cwd: process.cwd(),\n lang: getOxcLang(loader),\n sourceType: 'module',\n sourcemap: sourceMap,\n ...transformOptions,\n });\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n throw new Error(\n `[wyw-in-js] Oxc transform failed for ${args.path}: ${message}`\n );\n }\n\n if (oxcResult.errors.length > 0) {\n const details = oxcResult.errors\n .map((error) =>\n error.codeframe\n ? `${error.message}\\n${error.codeframe}`\n : error.message\n )\n .join('\\n');\n throw new Error(\n `[wyw-in-js] Oxc transform failed for ${args.path}: ${details}`\n );\n }\n\n codeForEsbuild = oxcResult.code;\n\n if (sourceMap && oxcResult.map) {\n const oxcMap = Buffer.from(\n JSON.stringify(oxcResult.map)\n ).toString('base64');\n codeForEsbuild += `/*# sourceMappingURL=data:application/json;base64,${oxcMap}*/`;\n }\n }\n }\n\n const transformed = esbuildTransformSync(codeForEsbuild, {\n ...options,\n sourcefile: args.path,\n sourcemap: sourceMap,\n loader,\n });\n let { code } = transformed;\n\n if (sourceMap) {\n const esbuildMap = Buffer.from(transformed.map).toString('base64');\n code += `/*# sourceMappingURL=data:application/json;base64,${esbuildMap}*/`;\n }\n\n const transformServices = {\n options: {\n filename: args.path,\n pluginOptions: rest,\n prefixer,\n keepComments,\n preprocessor,\n root: process.cwd(),\n },\n cache,\n eventEmitter: emitter,\n };\n\n const result = await transform(transformServices, code, asyncResolve);\n const resolveDir = dirname(args.path);\n\n if (typeof result.cssText === 'undefined') {\n return {\n contents: code,\n loader,\n resolveDir,\n };\n }\n\n if (result.cssText === '') {\n let contents = result.code;\n\n if (sourceMap && result.sourceMap) {\n const wywMap = Buffer.from(\n JSON.stringify(result.sourceMap)\n ).toString('base64');\n contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;\n }\n\n return {\n contents,\n loader,\n resolveDir,\n };\n }\n\n let { cssText } = result;\n\n const slug = slugify(cssText);\n const cssFilename = `${filename}_${slug}.wyw.css`;\n\n let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;\n\n if (sourceMap && result.cssSourceMapText) {\n const map = Buffer.from(result.cssSourceMapText).toString('base64');\n cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;\n const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;\n }\n\n cssLookup.set(cssFilename, cssText);\n cssResolveDirs.set(cssFilename, resolveDir);\n\n return {\n contents,\n loader,\n resolveDir,\n };\n });\n },\n };\n}\n"],"file":"index.mjs"}
|
package/package.json
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/esbuild",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"dependencies": {
|
|
5
|
-
"@wyw-in-js/shared": "
|
|
6
|
-
"@wyw-in-js/transform": "
|
|
6
|
+
"@wyw-in-js/shared": "2.0.0-alpha.0",
|
|
7
|
+
"@wyw-in-js/transform": "2.0.0-alpha.0",
|
|
8
|
+
"oxc-transform": "0.127.0"
|
|
7
9
|
},
|
|
8
10
|
"devDependencies": {
|
|
9
|
-
"@types/node": "^
|
|
10
|
-
"@wyw-in-js/babel-config": "workspace:*",
|
|
11
|
+
"@types/node": "^22.0.0",
|
|
11
12
|
"@wyw-in-js/eslint-config": "workspace:*",
|
|
12
13
|
"@wyw-in-js/ts-config": "workspace:*",
|
|
13
14
|
"esbuild": "^0.15.16"
|
|
14
15
|
},
|
|
15
16
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
17
|
+
"node": ">=22.0.0"
|
|
17
18
|
},
|
|
18
19
|
"exports": {
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./types/index.d.ts",
|
|
22
|
+
"default": "./esm/index.mjs"
|
|
23
|
+
}
|
|
22
24
|
},
|
|
23
25
|
"files": [
|
|
24
26
|
"esm/",
|
|
25
|
-
"lib/",
|
|
26
27
|
"types/"
|
|
27
28
|
],
|
|
28
29
|
"license": "MIT",
|
|
29
|
-
"main": "
|
|
30
|
+
"main": "esm/index.mjs",
|
|
30
31
|
"module": "esm/index.mjs",
|
|
31
32
|
"peerDependencies": {
|
|
32
33
|
"esbuild": ">=0.12.0"
|
|
@@ -35,8 +36,7 @@
|
|
|
35
36
|
"access": "public"
|
|
36
37
|
},
|
|
37
38
|
"scripts": {
|
|
38
|
-
"build:esm": "
|
|
39
|
-
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
39
|
+
"build:esm": "node ../../scripts/build-esm-oxc.mjs --out-file-extension .mjs",
|
|
40
40
|
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
|
|
41
41
|
"lint": "eslint --ext .js,.ts .",
|
|
42
42
|
"test": "bun test src"
|
package/types/index.d.ts
CHANGED
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
import type { Plugin, TransformOptions } from 'esbuild';
|
|
7
7
|
import type { PluginOptions, Preprocessor, IFileReporterOptions } from '@wyw-in-js/transform';
|
|
8
8
|
type EsbuildPluginOptions = {
|
|
9
|
-
babelTransform?: boolean;
|
|
10
9
|
debug?: IFileReporterOptions | false | null | undefined;
|
|
11
10
|
esbuildOptions?: TransformOptions;
|
|
12
11
|
filter?: RegExp | string;
|
|
13
12
|
keepComments?: boolean | RegExp;
|
|
13
|
+
oxcTransform?: boolean;
|
|
14
14
|
prefixer?: boolean;
|
|
15
15
|
preprocessor?: Preprocessor;
|
|
16
16
|
sourceMap?: boolean;
|
|
17
17
|
transformLibraries?: boolean;
|
|
18
18
|
} & Partial<PluginOptions>;
|
|
19
|
-
export default function wywInJS({
|
|
19
|
+
export default function wywInJS({ debug, sourceMap, keepComments, oxcTransform, prefixer, preprocessor, esbuildOptions, filter, transformLibraries, ...rest }?: EsbuildPluginOptions): Plugin;
|
|
20
20
|
export {};
|
package/types/index.js
CHANGED
|
@@ -1,44 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* This file contains an esbuild loader for wyw-in-js.
|
|
4
3
|
* It uses the transform.ts function to generate class names from source code,
|
|
5
4
|
* returns transformed code without template literals and attaches generated source maps
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const shared_1 = require("@wyw-in-js/shared");
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { dirname, isAbsolute, join, parse, posix } from 'path';
|
|
8
|
+
import { transformSync as esbuildTransformSync } from 'esbuild';
|
|
9
|
+
import { transformSync as oxcTransformSync, } from 'oxc-transform';
|
|
10
|
+
import { disposeEvalBroker, slugify, transform, TransformCacheCollection, createFileReporter, loadWywOptions, } from '@wyw-in-js/transform';
|
|
11
|
+
import { asyncResolverFactory } from '@wyw-in-js/shared';
|
|
14
12
|
const supportedFilterFlags = new Set(['i', 'm', 's']);
|
|
15
13
|
const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
|
|
16
|
-
function wywInJS({
|
|
14
|
+
export default function wywInJS({ debug, sourceMap, keepComments, oxcTransform, prefixer, preprocessor, esbuildOptions, filter = /\.(js|jsx|ts|tsx)$/, transformLibraries, ...rest } = {}) {
|
|
17
15
|
let options = esbuildOptions;
|
|
18
|
-
const cache = new
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
options: {
|
|
25
|
-
filename: '<wyw-in-js/esbuild>',
|
|
26
|
-
pluginOptions: resolvedWywOptions,
|
|
27
|
-
root: process.cwd(),
|
|
28
|
-
},
|
|
29
|
-
}).babel;
|
|
30
|
-
}
|
|
31
|
-
const createAsyncResolver = (0, shared_1.asyncResolverFactory)(async (resolved, token) => {
|
|
16
|
+
const cache = new TransformCacheCollection();
|
|
17
|
+
const shouldRunOxcTransform = oxcTransform ?? false;
|
|
18
|
+
const resolvedWywOptions = shouldRunOxcTransform
|
|
19
|
+
? loadWywOptions(rest)
|
|
20
|
+
: null;
|
|
21
|
+
const createAsyncResolver = asyncResolverFactory(async (resolved, token) => {
|
|
32
22
|
if (resolved.errors.length > 0) {
|
|
33
23
|
throw new Error(`Cannot resolve ${token}`);
|
|
34
24
|
}
|
|
35
|
-
return resolved.path.replace(/\\/g,
|
|
25
|
+
return resolved.path.replace(/\\/g, posix.sep);
|
|
36
26
|
}, (what, importer) => [
|
|
37
27
|
what,
|
|
38
28
|
{
|
|
39
|
-
resolveDir:
|
|
40
|
-
?
|
|
41
|
-
:
|
|
29
|
+
resolveDir: isAbsolute(importer)
|
|
30
|
+
? dirname(importer)
|
|
31
|
+
: join(process.cwd(), dirname(importer)),
|
|
42
32
|
kind: 'import-statement',
|
|
43
33
|
},
|
|
44
34
|
]);
|
|
@@ -48,8 +38,8 @@ function wywInJS({ babelTransform, debug, sourceMap, keepComments, prefixer, pre
|
|
|
48
38
|
const cssLookup = new Map();
|
|
49
39
|
const cssResolveDirs = new Map();
|
|
50
40
|
const warnedFilters = new Set();
|
|
51
|
-
let
|
|
52
|
-
const { emitter, onDone } =
|
|
41
|
+
let warnedEmptyOxcOptions = false;
|
|
42
|
+
const { emitter, onDone } = createFileReporter(debug ?? false);
|
|
53
43
|
const warnOnUnsupportedFlags = (filterRegexp, removedFlags, sanitizedFlags) => {
|
|
54
44
|
const key = `${filterRegexp.source}/${filterRegexp.flags}`;
|
|
55
45
|
if (warnedFilters.has(key)) {
|
|
@@ -78,9 +68,19 @@ function wywInJS({ babelTransform, debug, sourceMap, keepComments, prefixer, pre
|
|
|
78
68
|
warnOnUnsupportedFlags(filterRegexp, removedFlags, sanitizedFlags);
|
|
79
69
|
return new RegExp(filterRegexp.source, sanitizedFlags);
|
|
80
70
|
};
|
|
71
|
+
const getOxcLang = (loader) => {
|
|
72
|
+
if (loader === 'tsx')
|
|
73
|
+
return 'tsx';
|
|
74
|
+
if (loader === 'ts')
|
|
75
|
+
return 'ts';
|
|
76
|
+
if (loader === 'jsx')
|
|
77
|
+
return 'jsx';
|
|
78
|
+
return 'js';
|
|
79
|
+
};
|
|
81
80
|
const asyncResolve = createAsyncResolver(build.resolve);
|
|
82
81
|
build.onEnd(() => {
|
|
83
82
|
onDone(process.cwd());
|
|
83
|
+
disposeEvalBroker(cache);
|
|
84
84
|
});
|
|
85
85
|
build.onResolve({ filter: /\.wyw\.css$/ }, (args) => {
|
|
86
86
|
return {
|
|
@@ -99,8 +99,8 @@ function wywInJS({ babelTransform, debug, sourceMap, keepComments, prefixer, pre
|
|
|
99
99
|
? new RegExp(filter)
|
|
100
100
|
: sanitizeFilter(filter);
|
|
101
101
|
build.onLoad({ filter: filterRegexp }, async (args) => {
|
|
102
|
-
const rawCode =
|
|
103
|
-
const { ext, name: filename } =
|
|
102
|
+
const rawCode = readFileSync(args.path, 'utf8');
|
|
103
|
+
const { ext, name: filename } = parse(args.path);
|
|
104
104
|
const loader = ext.replace(/^\./, '');
|
|
105
105
|
if (!transformLibraries && nodeModulesRegex.test(args.path)) {
|
|
106
106
|
return {
|
|
@@ -118,44 +118,49 @@ function wywInJS({ babelTransform, debug, sourceMap, keepComments, prefixer, pre
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
let codeForEsbuild = rawCode;
|
|
121
|
-
if (
|
|
122
|
-
if (!
|
|
123
|
-
throw new Error('[wyw-in-js] Internal error:
|
|
121
|
+
if (shouldRunOxcTransform) {
|
|
122
|
+
if (!resolvedWywOptions) {
|
|
123
|
+
throw new Error('[wyw-in-js] Internal error: oxcTransform is enabled but WyW options are not initialized');
|
|
124
124
|
}
|
|
125
|
-
const
|
|
126
|
-
if (!Object.keys(
|
|
127
|
-
if (!
|
|
128
|
-
|
|
125
|
+
const transformOptions = resolvedWywOptions.oxcOptions.transform;
|
|
126
|
+
if (!transformOptions || !Object.keys(transformOptions).length) {
|
|
127
|
+
if (!warnedEmptyOxcOptions) {
|
|
128
|
+
warnedEmptyOxcOptions = true;
|
|
129
129
|
// eslint-disable-next-line no-console
|
|
130
|
-
console.warn('[wyw-in-js]
|
|
130
|
+
console.warn('[wyw-in-js] oxcTransform is enabled but oxcOptions.transform is empty; skipping Oxc transform.');
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
134
|
-
let
|
|
134
|
+
let oxcResult;
|
|
135
135
|
try {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
136
|
+
oxcResult = oxcTransformSync(args.path, codeForEsbuild, {
|
|
137
|
+
cwd: process.cwd(),
|
|
138
|
+
lang: getOxcLang(loader),
|
|
139
|
+
sourceType: 'module',
|
|
140
|
+
sourcemap: sourceMap,
|
|
141
|
+
...transformOptions,
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
catch (e) {
|
|
145
145
|
const message = e instanceof Error ? e.message : String(e);
|
|
146
|
-
throw new Error(`[wyw-in-js]
|
|
146
|
+
throw new Error(`[wyw-in-js] Oxc transform failed for ${args.path}: ${message}`);
|
|
147
147
|
}
|
|
148
|
-
if (
|
|
149
|
-
|
|
148
|
+
if (oxcResult.errors.length > 0) {
|
|
149
|
+
const details = oxcResult.errors
|
|
150
|
+
.map((error) => error.codeframe
|
|
151
|
+
? `${error.message}\n${error.codeframe}`
|
|
152
|
+
: error.message)
|
|
153
|
+
.join('\n');
|
|
154
|
+
throw new Error(`[wyw-in-js] Oxc transform failed for ${args.path}: ${details}`);
|
|
150
155
|
}
|
|
151
|
-
codeForEsbuild =
|
|
152
|
-
if (sourceMap &&
|
|
153
|
-
const
|
|
154
|
-
codeForEsbuild += `/*# sourceMappingURL=data:application/json;base64,${
|
|
156
|
+
codeForEsbuild = oxcResult.code;
|
|
157
|
+
if (sourceMap && oxcResult.map) {
|
|
158
|
+
const oxcMap = Buffer.from(JSON.stringify(oxcResult.map)).toString('base64');
|
|
159
|
+
codeForEsbuild += `/*# sourceMappingURL=data:application/json;base64,${oxcMap}*/`;
|
|
155
160
|
}
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
|
-
const transformed = (
|
|
163
|
+
const transformed = esbuildTransformSync(codeForEsbuild, {
|
|
159
164
|
...options,
|
|
160
165
|
sourcefile: args.path,
|
|
161
166
|
sourcemap: sourceMap,
|
|
@@ -178,8 +183,8 @@ function wywInJS({ babelTransform, debug, sourceMap, keepComments, prefixer, pre
|
|
|
178
183
|
cache,
|
|
179
184
|
eventEmitter: emitter,
|
|
180
185
|
};
|
|
181
|
-
const result = await
|
|
182
|
-
const resolveDir =
|
|
186
|
+
const result = await transform(transformServices, code, asyncResolve);
|
|
187
|
+
const resolveDir = dirname(args.path);
|
|
183
188
|
if (typeof result.cssText === 'undefined') {
|
|
184
189
|
return {
|
|
185
190
|
contents: code,
|
|
@@ -200,7 +205,7 @@ function wywInJS({ babelTransform, debug, sourceMap, keepComments, prefixer, pre
|
|
|
200
205
|
};
|
|
201
206
|
}
|
|
202
207
|
let { cssText } = result;
|
|
203
|
-
const slug =
|
|
208
|
+
const slug = slugify(cssText);
|
|
204
209
|
const cssFilename = `${filename}_${slug}.wyw.css`;
|
|
205
210
|
let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;
|
|
206
211
|
if (sourceMap && result.cssSourceMapText) {
|
package/lib/index.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = wywInJS;
|
|
7
|
-
var _fs = require("fs");
|
|
8
|
-
var _path = require("path");
|
|
9
|
-
var _esbuild = require("esbuild");
|
|
10
|
-
var _transform = require("@wyw-in-js/transform");
|
|
11
|
-
var _shared = require("@wyw-in-js/shared");
|
|
12
|
-
/**
|
|
13
|
-
* This file contains an esbuild loader for wyw-in-js.
|
|
14
|
-
* It uses the transform.ts function to generate class names from source code,
|
|
15
|
-
* returns transformed code without template literals and attaches generated source maps
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const supportedFilterFlags = new Set(['i', 'm', 's']);
|
|
19
|
-
const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
|
|
20
|
-
function wywInJS({
|
|
21
|
-
babelTransform,
|
|
22
|
-
debug,
|
|
23
|
-
sourceMap,
|
|
24
|
-
keepComments,
|
|
25
|
-
prefixer,
|
|
26
|
-
preprocessor,
|
|
27
|
-
esbuildOptions,
|
|
28
|
-
filter = /\.(js|jsx|ts|tsx)$/,
|
|
29
|
-
transformLibraries,
|
|
30
|
-
...rest
|
|
31
|
-
} = {}) {
|
|
32
|
-
let options = esbuildOptions;
|
|
33
|
-
const cache = new _transform.TransformCacheCollection();
|
|
34
|
-
let resolvedWywOptions = null;
|
|
35
|
-
let babel = null;
|
|
36
|
-
if (babelTransform) {
|
|
37
|
-
resolvedWywOptions = (0, _transform.loadWywOptions)(rest);
|
|
38
|
-
babel = (0, _transform.withDefaultServices)({
|
|
39
|
-
options: {
|
|
40
|
-
filename: '<wyw-in-js/esbuild>',
|
|
41
|
-
pluginOptions: resolvedWywOptions,
|
|
42
|
-
root: process.cwd()
|
|
43
|
-
}
|
|
44
|
-
}).babel;
|
|
45
|
-
}
|
|
46
|
-
const createAsyncResolver = (0, _shared.asyncResolverFactory)(async (resolved, token) => {
|
|
47
|
-
if (resolved.errors.length > 0) {
|
|
48
|
-
throw new Error(`Cannot resolve ${token}`);
|
|
49
|
-
}
|
|
50
|
-
return resolved.path.replace(/\\/g, _path.posix.sep);
|
|
51
|
-
}, (what, importer) => [what, {
|
|
52
|
-
resolveDir: (0, _path.isAbsolute)(importer) ? (0, _path.dirname)(importer) : (0, _path.join)(process.cwd(), (0, _path.dirname)(importer)),
|
|
53
|
-
kind: 'import-statement'
|
|
54
|
-
}]);
|
|
55
|
-
return {
|
|
56
|
-
name: 'wyw-in-js',
|
|
57
|
-
setup(build) {
|
|
58
|
-
const cssLookup = new Map();
|
|
59
|
-
const cssResolveDirs = new Map();
|
|
60
|
-
const warnedFilters = new Set();
|
|
61
|
-
let warnedEmptyBabelOptions = false;
|
|
62
|
-
const {
|
|
63
|
-
emitter,
|
|
64
|
-
onDone
|
|
65
|
-
} = (0, _transform.createFileReporter)(debug !== null && debug !== void 0 ? debug : false);
|
|
66
|
-
const warnOnUnsupportedFlags = (filterRegexp, removedFlags, sanitizedFlags) => {
|
|
67
|
-
const key = `${filterRegexp.source}/${filterRegexp.flags}`;
|
|
68
|
-
if (warnedFilters.has(key)) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
warnedFilters.add(key);
|
|
72
|
-
const nextFlags = sanitizedFlags || 'none';
|
|
73
|
-
// eslint-disable-next-line no-console
|
|
74
|
-
console.warn(`[wyw-in-js] Ignoring unsupported RegExp flags "${removedFlags}" ` + `in esbuild filter /${filterRegexp.source}/${filterRegexp.flags}. ` + `Using flags "${nextFlags}".`);
|
|
75
|
-
};
|
|
76
|
-
const sanitizeFilter = filterRegexp => {
|
|
77
|
-
const {
|
|
78
|
-
flags
|
|
79
|
-
} = filterRegexp;
|
|
80
|
-
const sanitizedFlags = flags.split('').filter(flag => supportedFilterFlags.has(flag)).join('');
|
|
81
|
-
if (sanitizedFlags === flags) {
|
|
82
|
-
return filterRegexp;
|
|
83
|
-
}
|
|
84
|
-
const removedFlags = flags.split('').filter(flag => !supportedFilterFlags.has(flag)).join('');
|
|
85
|
-
warnOnUnsupportedFlags(filterRegexp, removedFlags, sanitizedFlags);
|
|
86
|
-
return new RegExp(filterRegexp.source, sanitizedFlags);
|
|
87
|
-
};
|
|
88
|
-
const asyncResolve = createAsyncResolver(build.resolve);
|
|
89
|
-
build.onEnd(() => {
|
|
90
|
-
onDone(process.cwd());
|
|
91
|
-
});
|
|
92
|
-
build.onResolve({
|
|
93
|
-
filter: /\.wyw\.css$/
|
|
94
|
-
}, args => {
|
|
95
|
-
return {
|
|
96
|
-
namespace: 'wyw-in-js',
|
|
97
|
-
path: args.path
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
build.onLoad({
|
|
101
|
-
filter: /.*/,
|
|
102
|
-
namespace: 'wyw-in-js'
|
|
103
|
-
}, args => {
|
|
104
|
-
return {
|
|
105
|
-
contents: cssLookup.get(args.path),
|
|
106
|
-
loader: 'css',
|
|
107
|
-
resolveDir: cssResolveDirs.get(args.path)
|
|
108
|
-
};
|
|
109
|
-
});
|
|
110
|
-
const filterRegexp = typeof filter === 'string' ? new RegExp(filter) : sanitizeFilter(filter);
|
|
111
|
-
build.onLoad({
|
|
112
|
-
filter: filterRegexp
|
|
113
|
-
}, async args => {
|
|
114
|
-
const rawCode = (0, _fs.readFileSync)(args.path, 'utf8');
|
|
115
|
-
const {
|
|
116
|
-
ext,
|
|
117
|
-
name: filename
|
|
118
|
-
} = (0, _path.parse)(args.path);
|
|
119
|
-
const loader = ext.replace(/^\./, '');
|
|
120
|
-
if (!transformLibraries && nodeModulesRegex.test(args.path)) {
|
|
121
|
-
return {
|
|
122
|
-
loader,
|
|
123
|
-
contents: rawCode
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
if (!options) {
|
|
127
|
-
options = {};
|
|
128
|
-
if ('jsxFactory' in build.initialOptions) {
|
|
129
|
-
options.jsxFactory = build.initialOptions.jsxFactory;
|
|
130
|
-
}
|
|
131
|
-
if ('jsxFragment' in build.initialOptions) {
|
|
132
|
-
options.jsxFragment = build.initialOptions.jsxFragment;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
let codeForEsbuild = rawCode;
|
|
136
|
-
if (babelTransform) {
|
|
137
|
-
if (!babel || !resolvedWywOptions) {
|
|
138
|
-
throw new Error('[wyw-in-js] Internal error: babelTransform is enabled but Babel services are not initialized');
|
|
139
|
-
}
|
|
140
|
-
const {
|
|
141
|
-
babelOptions
|
|
142
|
-
} = resolvedWywOptions;
|
|
143
|
-
if (!Object.keys(babelOptions).length) {
|
|
144
|
-
if (!warnedEmptyBabelOptions) {
|
|
145
|
-
warnedEmptyBabelOptions = true;
|
|
146
|
-
// eslint-disable-next-line no-console
|
|
147
|
-
console.warn('[wyw-in-js] babelTransform is enabled but babelOptions is empty; skipping Babel transform.');
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
var _babelResult;
|
|
151
|
-
let babelResult;
|
|
152
|
-
try {
|
|
153
|
-
babelResult = babel.transformSync(codeForEsbuild, {
|
|
154
|
-
...babelOptions,
|
|
155
|
-
ast: false,
|
|
156
|
-
filename: args.path,
|
|
157
|
-
sourceFileName: args.path,
|
|
158
|
-
sourceMaps: sourceMap
|
|
159
|
-
});
|
|
160
|
-
} catch (e) {
|
|
161
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
162
|
-
throw new Error(`[wyw-in-js] Babel transform failed for ${args.path}: ${message}`);
|
|
163
|
-
}
|
|
164
|
-
if (!((_babelResult = babelResult) !== null && _babelResult !== void 0 && _babelResult.code)) {
|
|
165
|
-
throw new Error(`[wyw-in-js] Babel transform failed for ${args.path}`);
|
|
166
|
-
}
|
|
167
|
-
codeForEsbuild = babelResult.code;
|
|
168
|
-
if (sourceMap && babelResult.map) {
|
|
169
|
-
const babelMap = Buffer.from(JSON.stringify(babelResult.map)).toString('base64');
|
|
170
|
-
codeForEsbuild += `/*# sourceMappingURL=data:application/json;base64,${babelMap}*/`;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const transformed = (0, _esbuild.transformSync)(codeForEsbuild, {
|
|
175
|
-
...options,
|
|
176
|
-
sourcefile: args.path,
|
|
177
|
-
sourcemap: sourceMap,
|
|
178
|
-
loader
|
|
179
|
-
});
|
|
180
|
-
let {
|
|
181
|
-
code
|
|
182
|
-
} = transformed;
|
|
183
|
-
if (sourceMap) {
|
|
184
|
-
const esbuildMap = Buffer.from(transformed.map).toString('base64');
|
|
185
|
-
code += `/*# sourceMappingURL=data:application/json;base64,${esbuildMap}*/`;
|
|
186
|
-
}
|
|
187
|
-
const transformServices = {
|
|
188
|
-
options: {
|
|
189
|
-
filename: args.path,
|
|
190
|
-
pluginOptions: rest,
|
|
191
|
-
prefixer,
|
|
192
|
-
keepComments,
|
|
193
|
-
preprocessor,
|
|
194
|
-
root: process.cwd()
|
|
195
|
-
},
|
|
196
|
-
cache,
|
|
197
|
-
eventEmitter: emitter
|
|
198
|
-
};
|
|
199
|
-
const result = await (0, _transform.transform)(transformServices, code, asyncResolve);
|
|
200
|
-
const resolveDir = (0, _path.dirname)(args.path);
|
|
201
|
-
if (typeof result.cssText === 'undefined') {
|
|
202
|
-
return {
|
|
203
|
-
contents: code,
|
|
204
|
-
loader,
|
|
205
|
-
resolveDir
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
if (result.cssText === '') {
|
|
209
|
-
let contents = result.code;
|
|
210
|
-
if (sourceMap && result.sourceMap) {
|
|
211
|
-
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
212
|
-
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
contents,
|
|
216
|
-
loader,
|
|
217
|
-
resolveDir
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
let {
|
|
221
|
-
cssText
|
|
222
|
-
} = result;
|
|
223
|
-
const slug = (0, _transform.slugify)(cssText);
|
|
224
|
-
const cssFilename = `${filename}_${slug}.wyw.css`;
|
|
225
|
-
let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;
|
|
226
|
-
if (sourceMap && result.cssSourceMapText) {
|
|
227
|
-
const map = Buffer.from(result.cssSourceMapText).toString('base64');
|
|
228
|
-
cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
|
|
229
|
-
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
230
|
-
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
|
|
231
|
-
}
|
|
232
|
-
cssLookup.set(cssFilename, cssText);
|
|
233
|
-
cssResolveDirs.set(cssFilename, resolveDir);
|
|
234
|
-
return {
|
|
235
|
-
contents,
|
|
236
|
-
loader,
|
|
237
|
-
resolveDir
|
|
238
|
-
};
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_fs","require","_path","_esbuild","_transform","_shared","supportedFilterFlags","Set","nodeModulesRegex","wywInJS","babelTransform","debug","sourceMap","keepComments","prefixer","preprocessor","esbuildOptions","filter","transformLibraries","rest","options","cache","TransformCacheCollection","resolvedWywOptions","babel","loadWywOptions","withDefaultServices","filename","pluginOptions","root","process","cwd","createAsyncResolver","asyncResolverFactory","resolved","token","errors","length","Error","path","replace","posix","sep","what","importer","resolveDir","isAbsolute","dirname","join","kind","name","setup","build","cssLookup","Map","cssResolveDirs","warnedFilters","warnedEmptyBabelOptions","emitter","onDone","createFileReporter","warnOnUnsupportedFlags","filterRegexp","removedFlags","sanitizedFlags","key","source","flags","has","add","nextFlags","console","warn","sanitizeFilter","split","flag","RegExp","asyncResolve","resolve","onEnd","onResolve","args","namespace","onLoad","contents","get","loader","rawCode","readFileSync","ext","parse","test","initialOptions","jsxFactory","jsxFragment","codeForEsbuild","babelOptions","Object","keys","_babelResult","babelResult","transformSync","ast","sourceFileName","sourceMaps","e","message","String","code","map","babelMap","Buffer","from","JSON","stringify","toString","transformed","esbuildTransformSync","sourcefile","sourcemap","esbuildMap","transformServices","eventEmitter","result","transform","cssText","wywMap","slug","slugify","cssFilename","cssSourceMapText","set"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * This file contains an esbuild loader for wyw-in-js.\n * It uses the transform.ts function to generate class names from source code,\n * returns transformed code without template literals and attaches generated source maps\n */\n\nimport { readFileSync } from 'fs';\nimport { dirname, isAbsolute, join, parse, posix } from 'path';\n\nimport type { Plugin, TransformOptions, Loader } from 'esbuild';\nimport { transformSync as esbuildTransformSync } from 'esbuild';\n\nimport type {\n PluginOptions,\n Preprocessor,\n IFileReporterOptions,\n} from '@wyw-in-js/transform';\nimport {\n slugify,\n transform,\n TransformCacheCollection,\n createFileReporter,\n loadWywOptions,\n withDefaultServices,\n} from '@wyw-in-js/transform';\nimport { asyncResolverFactory } from '@wyw-in-js/shared';\n\ntype EsbuildPluginOptions = {\n babelTransform?: boolean;\n debug?: IFileReporterOptions | false | null | undefined;\n esbuildOptions?: TransformOptions;\n filter?: RegExp | string;\n keepComments?: boolean | RegExp;\n prefixer?: boolean;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n transformLibraries?: boolean;\n} & Partial<PluginOptions>;\n\nconst supportedFilterFlags = new Set(['i', 'm', 's']);\n\nconst nodeModulesRegex = /^(?:.*[\\\\/])?node_modules(?:[\\\\/].*)?$/;\n\nexport default function wywInJS({\n babelTransform,\n debug,\n sourceMap,\n keepComments,\n prefixer,\n preprocessor,\n esbuildOptions,\n filter = /\\.(js|jsx|ts|tsx)$/,\n transformLibraries,\n ...rest\n}: EsbuildPluginOptions = {}): Plugin {\n let options = esbuildOptions;\n const cache = new TransformCacheCollection();\n let resolvedWywOptions: ReturnType<typeof loadWywOptions> | null = null;\n let babel: ReturnType<typeof withDefaultServices>['babel'] | null = null;\n if (babelTransform) {\n resolvedWywOptions = loadWywOptions(rest);\n babel = withDefaultServices({\n options: {\n filename: '<wyw-in-js/esbuild>',\n pluginOptions: resolvedWywOptions,\n root: process.cwd(),\n },\n }).babel;\n }\n const createAsyncResolver = asyncResolverFactory(\n async (\n resolved: {\n errors: unknown[];\n path: string;\n },\n token: string\n ): Promise<string> => {\n if (resolved.errors.length > 0) {\n throw new Error(`Cannot resolve ${token}`);\n }\n\n return resolved.path.replace(/\\\\/g, posix.sep);\n },\n (what, importer) => [\n what,\n {\n resolveDir: isAbsolute(importer)\n ? dirname(importer)\n : join(process.cwd(), dirname(importer)),\n kind: 'import-statement',\n },\n ]\n );\n return {\n name: 'wyw-in-js',\n setup(build) {\n const cssLookup = new Map<string, string>();\n const cssResolveDirs = new Map<string, string>();\n const warnedFilters = new Set<string>();\n let warnedEmptyBabelOptions = false;\n\n const { emitter, onDone } = createFileReporter(debug ?? false);\n\n const warnOnUnsupportedFlags = (\n filterRegexp: RegExp,\n removedFlags: string,\n sanitizedFlags: string\n ) => {\n const key = `${filterRegexp.source}/${filterRegexp.flags}`;\n if (warnedFilters.has(key)) {\n return;\n }\n warnedFilters.add(key);\n const nextFlags = sanitizedFlags || 'none';\n // eslint-disable-next-line no-console\n console.warn(\n `[wyw-in-js] Ignoring unsupported RegExp flags \"${removedFlags}\" ` +\n `in esbuild filter /${filterRegexp.source}/${filterRegexp.flags}. ` +\n `Using flags \"${nextFlags}\".`\n );\n };\n\n const sanitizeFilter = (filterRegexp: RegExp): RegExp => {\n const { flags } = filterRegexp;\n const sanitizedFlags = flags\n .split('')\n .filter((flag) => supportedFilterFlags.has(flag))\n .join('');\n if (sanitizedFlags === flags) {\n return filterRegexp;\n }\n const removedFlags = flags\n .split('')\n .filter((flag) => !supportedFilterFlags.has(flag))\n .join('');\n warnOnUnsupportedFlags(filterRegexp, removedFlags, sanitizedFlags);\n return new RegExp(filterRegexp.source, sanitizedFlags);\n };\n\n const asyncResolve = createAsyncResolver(build.resolve);\n\n build.onEnd(() => {\n onDone(process.cwd());\n });\n\n build.onResolve({ filter: /\\.wyw\\.css$/ }, (args) => {\n return {\n namespace: 'wyw-in-js',\n path: args.path,\n };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, (args) => {\n return {\n contents: cssLookup.get(args.path),\n loader: 'css',\n resolveDir: cssResolveDirs.get(args.path),\n };\n });\n\n const filterRegexp =\n typeof filter === 'string'\n ? new RegExp(filter)\n : sanitizeFilter(filter);\n\n build.onLoad({ filter: filterRegexp }, async (args) => {\n const rawCode = readFileSync(args.path, 'utf8');\n const { ext, name: filename } = parse(args.path);\n const loader = ext.replace(/^\\./, '') as Loader;\n\n if (!transformLibraries && nodeModulesRegex.test(args.path)) {\n return {\n loader,\n contents: rawCode,\n };\n }\n\n if (!options) {\n options = {};\n if ('jsxFactory' in build.initialOptions) {\n options.jsxFactory = build.initialOptions.jsxFactory;\n }\n if ('jsxFragment' in build.initialOptions) {\n options.jsxFragment = build.initialOptions.jsxFragment;\n }\n }\n\n let codeForEsbuild = rawCode;\n if (babelTransform) {\n if (!babel || !resolvedWywOptions) {\n throw new Error(\n '[wyw-in-js] Internal error: babelTransform is enabled but Babel services are not initialized'\n );\n }\n\n const { babelOptions } = resolvedWywOptions;\n if (!Object.keys(babelOptions).length) {\n if (!warnedEmptyBabelOptions) {\n warnedEmptyBabelOptions = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[wyw-in-js] babelTransform is enabled but babelOptions is empty; skipping Babel transform.'\n );\n }\n } else {\n let babelResult;\n try {\n babelResult = babel.transformSync(codeForEsbuild, {\n ...babelOptions,\n ast: false,\n filename: args.path,\n sourceFileName: args.path,\n sourceMaps: sourceMap,\n });\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n throw new Error(\n `[wyw-in-js] Babel transform failed for ${args.path}: ${message}`\n );\n }\n\n if (!babelResult?.code) {\n throw new Error(\n `[wyw-in-js] Babel transform failed for ${args.path}`\n );\n }\n\n codeForEsbuild = babelResult.code;\n\n if (sourceMap && babelResult.map) {\n const babelMap = Buffer.from(\n JSON.stringify(babelResult.map)\n ).toString('base64');\n codeForEsbuild += `/*# sourceMappingURL=data:application/json;base64,${babelMap}*/`;\n }\n }\n }\n\n const transformed = esbuildTransformSync(codeForEsbuild, {\n ...options,\n sourcefile: args.path,\n sourcemap: sourceMap,\n loader,\n });\n let { code } = transformed;\n\n if (sourceMap) {\n const esbuildMap = Buffer.from(transformed.map).toString('base64');\n code += `/*# sourceMappingURL=data:application/json;base64,${esbuildMap}*/`;\n }\n\n const transformServices = {\n options: {\n filename: args.path,\n pluginOptions: rest,\n prefixer,\n keepComments,\n preprocessor,\n root: process.cwd(),\n },\n cache,\n eventEmitter: emitter,\n };\n\n const result = await transform(transformServices, code, asyncResolve);\n const resolveDir = dirname(args.path);\n\n if (typeof result.cssText === 'undefined') {\n return {\n contents: code,\n loader,\n resolveDir,\n };\n }\n\n if (result.cssText === '') {\n let contents = result.code;\n\n if (sourceMap && result.sourceMap) {\n const wywMap = Buffer.from(\n JSON.stringify(result.sourceMap)\n ).toString('base64');\n contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;\n }\n\n return {\n contents,\n loader,\n resolveDir,\n };\n }\n\n let { cssText } = result;\n\n const slug = slugify(cssText);\n const cssFilename = `${filename}_${slug}.wyw.css`;\n\n let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;\n\n if (sourceMap && result.cssSourceMapText) {\n const map = Buffer.from(result.cssSourceMapText).toString('base64');\n cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;\n const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;\n }\n\n cssLookup.set(cssFilename, cssText);\n cssResolveDirs.set(cssFilename, resolveDir);\n\n return {\n contents,\n loader,\n resolveDir,\n };\n });\n },\n };\n}\n"],"mappings":";;;;;;AAMA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAGA,IAAAE,QAAA,GAAAF,OAAA;AAOA,IAAAG,UAAA,GAAAH,OAAA;AAQA,IAAAI,OAAA,GAAAJ,OAAA;AAzBA;AACA;AACA;AACA;AACA;;AAmCA,MAAMK,oBAAoB,GAAG,IAAIC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,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