@wyw-in-js/bun 1.1.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/esm/index.mjs +158 -186
- package/esm/index.mjs.map +1 -1
- package/package.json +12 -13
- package/types/index.js +20 -26
- package/lib/index.js +0 -200
- package/lib/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -27,6 +27,15 @@ await Bun.build({
|
|
|
27
27
|
});
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Eval resolver modes
|
|
31
|
+
|
|
32
|
+
`eval.resolver: 'native'` and the native step of `eval.resolver: 'hybrid'` use `oxc-resolver` with automatic
|
|
33
|
+
`tsconfig.json` discovery.
|
|
34
|
+
|
|
35
|
+
The Bun plugin does not receive a static bundler alias map. Use `hybrid` when evaluated imports may rely on Bun-specific
|
|
36
|
+
resolution. Use `native` only when `oxc-resolver` can resolve all evaluated imports, or mirror Bun-only aliases in
|
|
37
|
+
`oxcOptions.resolver.alias`.
|
|
38
|
+
|
|
30
39
|
## Transforming libraries in `node_modules`
|
|
31
40
|
|
|
32
41
|
By default, the Bun plugin skips transforming files from `node_modules` for performance.
|
package/esm/index.mjs
CHANGED
|
@@ -1,192 +1,164 @@
|
|
|
1
|
-
import { readFileSync } from
|
|
2
|
-
import path from
|
|
3
|
-
import { createFilter } from
|
|
4
|
-
import { resolveSync, Transpiler } from
|
|
5
|
-
import { asyncResolveFallback } from
|
|
6
|
-
import { createFileReporter, slugify, transform, TransformCacheCollection } from
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
4
|
+
import { resolveSync, Transpiler } from "bun";
|
|
5
|
+
import { asyncResolveFallback } from "@wyw-in-js/shared";
|
|
6
|
+
import { createFileReporter, slugify, transform, TransformCacheCollection } from "@wyw-in-js/transform";
|
|
7
7
|
const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
|
|
8
8
|
function getLoader(filename) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return 'tsx';
|
|
19
|
-
default:
|
|
20
|
-
return 'js';
|
|
21
|
-
}
|
|
9
|
+
const ext = path.extname(filename);
|
|
10
|
+
switch (ext) {
|
|
11
|
+
case ".jsx": return "jsx";
|
|
12
|
+
case ".ts":
|
|
13
|
+
case ".mts":
|
|
14
|
+
case ".cts": return "ts";
|
|
15
|
+
case ".tsx": return "tsx";
|
|
16
|
+
default: return "js";
|
|
17
|
+
}
|
|
22
18
|
}
|
|
23
19
|
function splitQueryAndHash(request) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
20
|
+
const queryIdx = request.indexOf("?");
|
|
21
|
+
const hashIdx = request.indexOf("#");
|
|
22
|
+
if (queryIdx === -1 && hashIdx === -1) {
|
|
23
|
+
return {
|
|
24
|
+
specifier: request,
|
|
25
|
+
suffix: ""
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
let startIdx;
|
|
29
|
+
if (queryIdx === -1) {
|
|
30
|
+
startIdx = hashIdx;
|
|
31
|
+
} else if (hashIdx === -1) {
|
|
32
|
+
startIdx = queryIdx;
|
|
33
|
+
} else {
|
|
34
|
+
startIdx = Math.min(queryIdx, hashIdx);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
specifier: request.slice(0, startIdx),
|
|
38
|
+
suffix: request.slice(startIdx)
|
|
39
|
+
};
|
|
44
40
|
}
|
|
45
|
-
export default function wywInJS({
|
|
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
|
-
contents,
|
|
168
|
-
loader
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
const slug = slugify(cssText);
|
|
172
|
-
const cssFilename = `${args.path.replace(/\.[cm]?[jt]sx?$/, '')}_${slug}.wyw.css`.replace(/\\/g, path.posix.sep);
|
|
173
|
-
let nextCssText = cssText;
|
|
174
|
-
let contents = `${result.code}\nimport ${JSON.stringify(cssFilename)};\n`;
|
|
175
|
-
if (sourceMap && result.cssSourceMapText) {
|
|
176
|
-
const map = Buffer.from(result.cssSourceMapText).toString('base64');
|
|
177
|
-
nextCssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
|
|
178
|
-
}
|
|
179
|
-
if (sourceMap && result.sourceMap) {
|
|
180
|
-
const map = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
181
|
-
contents += `//# sourceMappingURL=data:application/json;base64,${map}\n`;
|
|
182
|
-
}
|
|
183
|
-
cssLookup.set(cssFilename, nextCssText);
|
|
184
|
-
return {
|
|
185
|
-
contents,
|
|
186
|
-
loader
|
|
187
|
-
};
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
};
|
|
41
|
+
export default function wywInJS({ debug, include, exclude, filter = /\.[cm]?[jt]sx?$/, nodeModules = false, transformLibraries, sourceMap, keepComments, prefixer, preprocessor, ...rest } = {}) {
|
|
42
|
+
const cache = new TransformCacheCollection();
|
|
43
|
+
const filterFn = createFilter(include, exclude);
|
|
44
|
+
const allowNodeModules = transformLibraries ?? nodeModules;
|
|
45
|
+
return {
|
|
46
|
+
name: "wyw-in-js",
|
|
47
|
+
setup(build) {
|
|
48
|
+
const cssLookup = new Map();
|
|
49
|
+
const emittedWarnings = new Set();
|
|
50
|
+
const { emitter, onDone } = createFileReporter(debug ?? false);
|
|
51
|
+
const transpilers = new Map();
|
|
52
|
+
const getTranspiler = (loader) => {
|
|
53
|
+
const cached = transpilers.get(loader);
|
|
54
|
+
if (cached) {
|
|
55
|
+
return cached;
|
|
56
|
+
}
|
|
57
|
+
const created = new Transpiler({
|
|
58
|
+
loader,
|
|
59
|
+
autoImportJSX: true
|
|
60
|
+
});
|
|
61
|
+
transpilers.set(loader, created);
|
|
62
|
+
return created;
|
|
63
|
+
};
|
|
64
|
+
const asyncResolve = async (what, importer, stack) => {
|
|
65
|
+
const { specifier, suffix } = splitQueryAndHash(what);
|
|
66
|
+
try {
|
|
67
|
+
return (await asyncResolveFallback(specifier, importer, stack)).replace(/\\/g, path.posix.sep).concat(suffix);
|
|
68
|
+
} catch {
|
|
69
|
+
return resolveSync(specifier, importer).replace(/\\/g, path.posix.sep).concat(suffix);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const emitWarning = (message) => {
|
|
73
|
+
const match = message.match(/\nconfig key: (.+)\n/);
|
|
74
|
+
const key = match?.[1] ?? message;
|
|
75
|
+
if (emittedWarnings.has(key)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
emittedWarnings.add(key);
|
|
79
|
+
// eslint-disable-next-line no-console
|
|
80
|
+
console.warn(message);
|
|
81
|
+
};
|
|
82
|
+
build.onEnd(() => {
|
|
83
|
+
onDone(process.cwd());
|
|
84
|
+
});
|
|
85
|
+
build.onResolve({ filter: /\.wyw\.css$/ }, (args) => ({
|
|
86
|
+
namespace: "wyw-in-js",
|
|
87
|
+
path: args.path
|
|
88
|
+
}));
|
|
89
|
+
build.onLoad({
|
|
90
|
+
filter: /.*/,
|
|
91
|
+
namespace: "wyw-in-js"
|
|
92
|
+
}, async (args) => {
|
|
93
|
+
const contents = cssLookup.get(args.path);
|
|
94
|
+
if (typeof contents === "undefined") {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
contents,
|
|
99
|
+
loader: "css"
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
const filterRegexp = typeof filter === "string" ? new RegExp(filter) : filter;
|
|
103
|
+
build.onLoad({ filter: filterRegexp }, async (args) => {
|
|
104
|
+
if (!filterFn(args.path)) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
if (!allowNodeModules && nodeModulesRegex.test(args.path)) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const rawCode = readFileSync(args.path, "utf8");
|
|
111
|
+
const loader = getLoader(args.path);
|
|
112
|
+
const transpiler = getTranspiler(loader);
|
|
113
|
+
const code = transpiler.transformSync(rawCode);
|
|
114
|
+
const transformServices = {
|
|
115
|
+
options: {
|
|
116
|
+
filename: args.path,
|
|
117
|
+
pluginOptions: rest,
|
|
118
|
+
prefixer,
|
|
119
|
+
keepComments,
|
|
120
|
+
preprocessor,
|
|
121
|
+
root: process.cwd()
|
|
122
|
+
},
|
|
123
|
+
cache,
|
|
124
|
+
emitWarning,
|
|
125
|
+
eventEmitter: emitter
|
|
126
|
+
};
|
|
127
|
+
const result = await transform(transformServices, code, asyncResolve);
|
|
128
|
+
const { cssText } = result;
|
|
129
|
+
if (typeof cssText === "undefined") {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
if (cssText === "") {
|
|
133
|
+
let contents = result.code;
|
|
134
|
+
if (sourceMap && result.sourceMap) {
|
|
135
|
+
const map = Buffer.from(JSON.stringify(result.sourceMap)).toString("base64");
|
|
136
|
+
contents += `\n//# sourceMappingURL=data:application/json;base64,${map}`;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
contents,
|
|
140
|
+
loader
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const slug = slugify(cssText);
|
|
144
|
+
const cssFilename = `${args.path.replace(/\.[cm]?[jt]sx?$/, "")}_${slug}.wyw.css`.replace(/\\/g, path.posix.sep);
|
|
145
|
+
let nextCssText = cssText;
|
|
146
|
+
let contents = `${result.code}\nimport ${JSON.stringify(cssFilename)};\n`;
|
|
147
|
+
if (sourceMap && result.cssSourceMapText) {
|
|
148
|
+
const map = Buffer.from(result.cssSourceMapText).toString("base64");
|
|
149
|
+
nextCssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
|
|
150
|
+
}
|
|
151
|
+
if (sourceMap && result.sourceMap) {
|
|
152
|
+
const map = Buffer.from(JSON.stringify(result.sourceMap)).toString("base64");
|
|
153
|
+
contents += `//# sourceMappingURL=data:application/json;base64,${map}\n`;
|
|
154
|
+
}
|
|
155
|
+
cssLookup.set(cssFilename, nextCssText);
|
|
156
|
+
return {
|
|
157
|
+
contents,
|
|
158
|
+
loader
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
191
163
|
}
|
|
192
|
-
//# sourceMappingURL=index.mjs.map
|
|
164
|
+
//# sourceMappingURL=index.mjs.map
|
package/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["readFileSync","path","createFilter","resolveSync","Transpiler","asyncResolveFallback","createFileReporter","slugify","transform","TransformCacheCollection","nodeModulesRegex","getLoader","filename","ext","extname","splitQueryAndHash","request","queryIdx","indexOf","hashIdx","specifier","suffix","startIdx","Math","min","slice","wywInJS","debug","include","exclude","filter","nodeModules","transformLibraries","sourceMap","keepComments","prefixer","preprocessor","rest","cache","filterFn","allowNodeModules","name","setup","build","cssLookup","Map","emittedWarnings","Set","emitter","onDone","transpilers","getTranspiler","loader","cached","get","created","autoImportJSX","set","asyncResolve","what","importer","stack","replace","posix","sep","concat","emitWarning","message","match","key","has","add","console","warn","onEnd","process","cwd","onResolve","args","namespace","onLoad","contents","undefined","filterRegexp","RegExp","test","rawCode","transpiler","code","transformSync","transformServices","options","pluginOptions","root","eventEmitter","result","cssText","map","Buffer","from","JSON","stringify","toString","slug","cssFilename","nextCssText","cssSourceMapText"],"sources":["../src/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport path from 'path';\n\nimport { createFilter } from '@rollup/pluginutils';\nimport type { FilterPattern } from '@rollup/pluginutils';\nimport type { BunPlugin, JavaScriptLoader, PluginBuilder } from 'bun';\nimport { resolveSync, Transpiler } from 'bun';\n\nimport { asyncResolveFallback } from '@wyw-in-js/shared';\nimport type {\n IFileReporterOptions,\n PluginOptions,\n Preprocessor,\n} from '@wyw-in-js/transform';\nimport {\n createFileReporter,\n slugify,\n transform,\n TransformCacheCollection,\n} from '@wyw-in-js/transform';\n\nexport type BunPluginOptions = {\n debug?: IFileReporterOptions | false | null | undefined;\n exclude?: FilterPattern;\n filter?: RegExp | string;\n include?: FilterPattern;\n keepComments?: boolean | RegExp;\n nodeModules?: boolean;\n prefixer?: boolean;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n transformLibraries?: boolean;\n} & Partial<PluginOptions>;\n\nconst nodeModulesRegex = /^(?:.*[\\\\/])?node_modules(?:[\\\\/].*)?$/;\n\nfunction getLoader(filename: string): JavaScriptLoader {\n const ext = path.extname(filename);\n switch (ext) {\n case '.jsx':\n return 'jsx';\n case '.ts':\n case '.mts':\n case '.cts':\n return 'ts';\n case '.tsx':\n return 'tsx';\n default:\n return 'js';\n }\n}\n\nfunction splitQueryAndHash(request: string): {\n specifier: string;\n suffix: string;\n} {\n const queryIdx = request.indexOf('?');\n const hashIdx = request.indexOf('#');\n\n if (queryIdx === -1 && hashIdx === -1) {\n return { specifier: request, suffix: '' };\n }\n\n let startIdx: number;\n if (queryIdx === -1) {\n startIdx = hashIdx;\n } else if (hashIdx === -1) {\n startIdx = queryIdx;\n } else {\n startIdx = Math.min(queryIdx, hashIdx);\n }\n\n return {\n specifier: request.slice(0, startIdx),\n suffix: request.slice(startIdx),\n };\n}\n\nexport default function wywInJS({\n debug,\n include,\n exclude,\n filter = /\\.[cm]?[jt]sx?$/,\n nodeModules = false,\n transformLibraries,\n sourceMap,\n keepComments,\n prefixer,\n preprocessor,\n ...rest\n}: BunPluginOptions = {}): BunPlugin {\n const cache = new TransformCacheCollection();\n const filterFn = createFilter(include, exclude);\n const allowNodeModules = transformLibraries ?? nodeModules;\n\n return {\n name: 'wyw-in-js',\n setup(build: PluginBuilder) {\n const cssLookup = new Map<string, string>();\n const emittedWarnings = new Set<string>();\n\n const { emitter, onDone } = createFileReporter(debug ?? false);\n\n const transpilers = new Map<\n JavaScriptLoader,\n InstanceType<typeof Transpiler>\n >();\n const getTranspiler = (\n loader: JavaScriptLoader\n ): InstanceType<typeof Transpiler> => {\n const cached = transpilers.get(loader);\n if (cached) {\n return cached;\n }\n\n const created = new Transpiler({ loader, autoImportJSX: true });\n transpilers.set(loader, created);\n return created;\n };\n\n const asyncResolve = async (\n what: string,\n importer: string,\n stack: string[]\n ): Promise<string | null> => {\n const { specifier, suffix } = splitQueryAndHash(what);\n try {\n return (await asyncResolveFallback(specifier, importer, stack))\n .replace(/\\\\/g, path.posix.sep)\n .concat(suffix);\n } catch {\n return resolveSync(specifier, importer)\n .replace(/\\\\/g, path.posix.sep)\n .concat(suffix);\n }\n };\n\n const emitWarning = (message: string) => {\n const match = message.match(/\\nconfig key: (.+)\\n/);\n const key = match?.[1] ?? message;\n if (emittedWarnings.has(key)) {\n return;\n }\n\n emittedWarnings.add(key);\n // eslint-disable-next-line no-console\n console.warn(message);\n };\n\n build.onEnd(() => {\n onDone(process.cwd());\n });\n\n build.onResolve({ filter: /\\.wyw\\.css$/ }, (args) => ({\n namespace: 'wyw-in-js',\n path: args.path,\n }));\n\n build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, async (args) => {\n const contents = cssLookup.get(args.path);\n if (typeof contents === 'undefined') {\n return undefined;\n }\n\n return {\n contents,\n loader: 'css',\n };\n });\n\n const filterRegexp =\n typeof filter === 'string' ? new RegExp(filter) : filter;\n\n build.onLoad({ filter: filterRegexp }, async (args) => {\n if (!filterFn(args.path)) {\n return undefined;\n }\n\n if (!allowNodeModules && nodeModulesRegex.test(args.path)) {\n return undefined;\n }\n\n const rawCode = readFileSync(args.path, 'utf8');\n const loader = getLoader(args.path);\n const transpiler = getTranspiler(loader);\n\n const code = transpiler.transformSync(rawCode);\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 emitWarning,\n eventEmitter: emitter,\n };\n\n const result = await transform(transformServices, code, asyncResolve);\n\n const { cssText } = result;\n\n if (typeof cssText === 'undefined') {\n return undefined;\n }\n\n if (cssText === '') {\n let contents = result.code;\n\n if (sourceMap && result.sourceMap) {\n const map = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `\\n//# sourceMappingURL=data:application/json;base64,${map}`;\n }\n\n return {\n contents,\n loader,\n };\n }\n\n const slug = slugify(cssText);\n const cssFilename = `${args.path.replace(\n /\\.[cm]?[jt]sx?$/,\n ''\n )}_${slug}.wyw.css`.replace(/\\\\/g, path.posix.sep);\n\n let nextCssText = cssText;\n let contents = `${result.code}\\nimport ${JSON.stringify(\n cssFilename\n )};\\n`;\n\n if (sourceMap && result.cssSourceMapText) {\n const map = Buffer.from(result.cssSourceMapText).toString('base64');\n nextCssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;\n }\n\n if (sourceMap && result.sourceMap) {\n const map = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `//# sourceMappingURL=data:application/json;base64,${map}\\n`;\n }\n\n cssLookup.set(cssFilename, nextCssText);\n\n return {\n contents,\n loader,\n };\n });\n },\n };\n}\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,IAAI;AACjC,OAAOC,IAAI,MAAM,MAAM;AAEvB,SAASC,YAAY,QAAQ,qBAAqB;AAGlD,SAASC,WAAW,EAAEC,UAAU,QAAQ,KAAK;AAE7C,SAASC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xD,SACD;AACD,iBAAY,qDAAqD,IAAI;;AAGvE,cAAU,IAAI,aAAa,YAAY;AAEvC,WAAO;KACL;KACA;KACD;KACD;;EAEL","names":[],"sources":["../src/index.ts"],"version":3,"sourcesContent":["import { readFileSync } from 'fs';\nimport path from 'path';\n\nimport { createFilter } from '@rollup/pluginutils';\nimport type { FilterPattern } from '@rollup/pluginutils';\nimport type { BunPlugin, JavaScriptLoader, PluginBuilder } from 'bun';\nimport { resolveSync, Transpiler } from 'bun';\n\nimport { asyncResolveFallback } from '@wyw-in-js/shared';\nimport type {\n IFileReporterOptions,\n PluginOptions,\n Preprocessor,\n} from '@wyw-in-js/transform';\nimport {\n createFileReporter,\n slugify,\n transform,\n TransformCacheCollection,\n} from '@wyw-in-js/transform';\n\nexport type BunPluginOptions = {\n debug?: IFileReporterOptions | false | null | undefined;\n exclude?: FilterPattern;\n filter?: RegExp | string;\n include?: FilterPattern;\n keepComments?: boolean | RegExp;\n nodeModules?: boolean;\n prefixer?: boolean;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n transformLibraries?: boolean;\n} & Partial<PluginOptions>;\n\nconst nodeModulesRegex = /^(?:.*[\\\\/])?node_modules(?:[\\\\/].*)?$/;\n\nfunction getLoader(filename: string): JavaScriptLoader {\n const ext = path.extname(filename);\n switch (ext) {\n case '.jsx':\n return 'jsx';\n case '.ts':\n case '.mts':\n case '.cts':\n return 'ts';\n case '.tsx':\n return 'tsx';\n default:\n return 'js';\n }\n}\n\nfunction splitQueryAndHash(request: string): {\n specifier: string;\n suffix: string;\n} {\n const queryIdx = request.indexOf('?');\n const hashIdx = request.indexOf('#');\n\n if (queryIdx === -1 && hashIdx === -1) {\n return { specifier: request, suffix: '' };\n }\n\n let startIdx: number;\n if (queryIdx === -1) {\n startIdx = hashIdx;\n } else if (hashIdx === -1) {\n startIdx = queryIdx;\n } else {\n startIdx = Math.min(queryIdx, hashIdx);\n }\n\n return {\n specifier: request.slice(0, startIdx),\n suffix: request.slice(startIdx),\n };\n}\n\nexport default function wywInJS({\n debug,\n include,\n exclude,\n filter = /\\.[cm]?[jt]sx?$/,\n nodeModules = false,\n transformLibraries,\n sourceMap,\n keepComments,\n prefixer,\n preprocessor,\n ...rest\n}: BunPluginOptions = {}): BunPlugin {\n const cache = new TransformCacheCollection();\n const filterFn = createFilter(include, exclude);\n const allowNodeModules = transformLibraries ?? nodeModules;\n\n return {\n name: 'wyw-in-js',\n setup(build: PluginBuilder) {\n const cssLookup = new Map<string, string>();\n const emittedWarnings = new Set<string>();\n\n const { emitter, onDone } = createFileReporter(debug ?? false);\n\n const transpilers = new Map<\n JavaScriptLoader,\n InstanceType<typeof Transpiler>\n >();\n const getTranspiler = (\n loader: JavaScriptLoader\n ): InstanceType<typeof Transpiler> => {\n const cached = transpilers.get(loader);\n if (cached) {\n return cached;\n }\n\n const created = new Transpiler({ loader, autoImportJSX: true });\n transpilers.set(loader, created);\n return created;\n };\n\n const asyncResolve = async (\n what: string,\n importer: string,\n stack: string[]\n ): Promise<string | null> => {\n const { specifier, suffix } = splitQueryAndHash(what);\n try {\n return (await asyncResolveFallback(specifier, importer, stack))\n .replace(/\\\\/g, path.posix.sep)\n .concat(suffix);\n } catch {\n return resolveSync(specifier, importer)\n .replace(/\\\\/g, path.posix.sep)\n .concat(suffix);\n }\n };\n\n const emitWarning = (message: string) => {\n const match = message.match(/\\nconfig key: (.+)\\n/);\n const key = match?.[1] ?? message;\n if (emittedWarnings.has(key)) {\n return;\n }\n\n emittedWarnings.add(key);\n // eslint-disable-next-line no-console\n console.warn(message);\n };\n\n build.onEnd(() => {\n onDone(process.cwd());\n });\n\n build.onResolve({ filter: /\\.wyw\\.css$/ }, (args) => ({\n namespace: 'wyw-in-js',\n path: args.path,\n }));\n\n build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, async (args) => {\n const contents = cssLookup.get(args.path);\n if (typeof contents === 'undefined') {\n return undefined;\n }\n\n return {\n contents,\n loader: 'css',\n };\n });\n\n const filterRegexp =\n typeof filter === 'string' ? new RegExp(filter) : filter;\n\n build.onLoad({ filter: filterRegexp }, async (args) => {\n if (!filterFn(args.path)) {\n return undefined;\n }\n\n if (!allowNodeModules && nodeModulesRegex.test(args.path)) {\n return undefined;\n }\n\n const rawCode = readFileSync(args.path, 'utf8');\n const loader = getLoader(args.path);\n const transpiler = getTranspiler(loader);\n\n const code = transpiler.transformSync(rawCode);\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 emitWarning,\n eventEmitter: emitter,\n };\n\n const result = await transform(transformServices, code, asyncResolve);\n\n const { cssText } = result;\n\n if (typeof cssText === 'undefined') {\n return undefined;\n }\n\n if (cssText === '') {\n let contents = result.code;\n\n if (sourceMap && result.sourceMap) {\n const map = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `\\n//# sourceMappingURL=data:application/json;base64,${map}`;\n }\n\n return {\n contents,\n loader,\n };\n }\n\n const slug = slugify(cssText);\n const cssFilename = `${args.path.replace(\n /\\.[cm]?[jt]sx?$/,\n ''\n )}_${slug}.wyw.css`.replace(/\\\\/g, path.posix.sep);\n\n let nextCssText = cssText;\n let contents = `${result.code}\\nimport ${JSON.stringify(\n cssFilename\n )};\\n`;\n\n if (sourceMap && result.cssSourceMapText) {\n const map = Buffer.from(result.cssSourceMapText).toString('base64');\n nextCssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;\n }\n\n if (sourceMap && result.sourceMap) {\n const map = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `//# sourceMappingURL=data:application/json;base64,${map}\\n`;\n }\n\n cssLookup.set(cssFilename, nextCssText);\n\n return {\n contents,\n loader,\n };\n });\n },\n };\n}\n"],"file":"index.mjs"}
|
package/package.json
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/bun",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"dependencies": {
|
|
5
6
|
"@rollup/pluginutils": "^5.1.4",
|
|
6
7
|
"bun-types": "^1.3.5",
|
|
7
|
-
"@wyw-in-js/shared": "
|
|
8
|
-
"@wyw-in-js/transform": "
|
|
8
|
+
"@wyw-in-js/shared": "2.0.0-alpha.1",
|
|
9
|
+
"@wyw-in-js/transform": "2.0.0-alpha.1"
|
|
9
10
|
},
|
|
10
11
|
"devDependencies": {
|
|
11
|
-
"@types/node": "^
|
|
12
|
-
"@wyw-in-js/babel-config": "workspace:*",
|
|
12
|
+
"@types/node": "^22.0.0",
|
|
13
13
|
"@wyw-in-js/eslint-config": "workspace:*",
|
|
14
14
|
"@wyw-in-js/ts-config": "workspace:*"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
17
|
+
"node": ">=22.0.0"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./types/index.d.ts",
|
|
22
|
+
"default": "./esm/index.mjs"
|
|
23
|
+
}
|
|
23
24
|
},
|
|
24
25
|
"files": [
|
|
25
26
|
"esm/",
|
|
26
|
-
"lib/",
|
|
27
27
|
"types/"
|
|
28
28
|
],
|
|
29
29
|
"license": "MIT",
|
|
30
|
-
"main": "
|
|
30
|
+
"main": "esm/index.mjs",
|
|
31
31
|
"module": "esm/index.mjs",
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build:esm": "
|
|
37
|
-
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
36
|
+
"build:esm": "node ../../scripts/build-esm-oxc.mjs --out-file-extension .mjs",
|
|
38
37
|
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
|
|
39
38
|
"lint": "eslint --ext .js,.ts .",
|
|
40
39
|
"test": "bun test src"
|
package/types/index.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const pluginutils_1 = require("@rollup/pluginutils");
|
|
10
|
-
const bun_1 = require("bun");
|
|
11
|
-
const shared_1 = require("@wyw-in-js/shared");
|
|
12
|
-
const transform_1 = require("@wyw-in-js/transform");
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
4
|
+
import { resolveSync, Transpiler } from 'bun';
|
|
5
|
+
import { asyncResolveFallback } from '@wyw-in-js/shared';
|
|
6
|
+
import { createFileReporter, slugify, transform, TransformCacheCollection, } from '@wyw-in-js/transform';
|
|
13
7
|
const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
|
|
14
8
|
function getLoader(filename) {
|
|
15
|
-
const ext =
|
|
9
|
+
const ext = path.extname(filename);
|
|
16
10
|
switch (ext) {
|
|
17
11
|
case '.jsx':
|
|
18
12
|
return 'jsx';
|
|
@@ -47,36 +41,36 @@ function splitQueryAndHash(request) {
|
|
|
47
41
|
suffix: request.slice(startIdx),
|
|
48
42
|
};
|
|
49
43
|
}
|
|
50
|
-
function wywInJS({ debug, include, exclude, filter = /\.[cm]?[jt]sx?$/, nodeModules = false, transformLibraries, sourceMap, keepComments, prefixer, preprocessor, ...rest } = {}) {
|
|
51
|
-
const cache = new
|
|
52
|
-
const filterFn =
|
|
44
|
+
export default function wywInJS({ debug, include, exclude, filter = /\.[cm]?[jt]sx?$/, nodeModules = false, transformLibraries, sourceMap, keepComments, prefixer, preprocessor, ...rest } = {}) {
|
|
45
|
+
const cache = new TransformCacheCollection();
|
|
46
|
+
const filterFn = createFilter(include, exclude);
|
|
53
47
|
const allowNodeModules = transformLibraries ?? nodeModules;
|
|
54
48
|
return {
|
|
55
49
|
name: 'wyw-in-js',
|
|
56
50
|
setup(build) {
|
|
57
51
|
const cssLookup = new Map();
|
|
58
52
|
const emittedWarnings = new Set();
|
|
59
|
-
const { emitter, onDone } =
|
|
53
|
+
const { emitter, onDone } = createFileReporter(debug ?? false);
|
|
60
54
|
const transpilers = new Map();
|
|
61
55
|
const getTranspiler = (loader) => {
|
|
62
56
|
const cached = transpilers.get(loader);
|
|
63
57
|
if (cached) {
|
|
64
58
|
return cached;
|
|
65
59
|
}
|
|
66
|
-
const created = new
|
|
60
|
+
const created = new Transpiler({ loader, autoImportJSX: true });
|
|
67
61
|
transpilers.set(loader, created);
|
|
68
62
|
return created;
|
|
69
63
|
};
|
|
70
64
|
const asyncResolve = async (what, importer, stack) => {
|
|
71
65
|
const { specifier, suffix } = splitQueryAndHash(what);
|
|
72
66
|
try {
|
|
73
|
-
return (await
|
|
74
|
-
.replace(/\\/g,
|
|
67
|
+
return (await asyncResolveFallback(specifier, importer, stack))
|
|
68
|
+
.replace(/\\/g, path.posix.sep)
|
|
75
69
|
.concat(suffix);
|
|
76
70
|
}
|
|
77
71
|
catch {
|
|
78
|
-
return
|
|
79
|
-
.replace(/\\/g,
|
|
72
|
+
return resolveSync(specifier, importer)
|
|
73
|
+
.replace(/\\/g, path.posix.sep)
|
|
80
74
|
.concat(suffix);
|
|
81
75
|
}
|
|
82
76
|
};
|
|
@@ -115,7 +109,7 @@ function wywInJS({ debug, include, exclude, filter = /\.[cm]?[jt]sx?$/, nodeModu
|
|
|
115
109
|
if (!allowNodeModules && nodeModulesRegex.test(args.path)) {
|
|
116
110
|
return undefined;
|
|
117
111
|
}
|
|
118
|
-
const rawCode =
|
|
112
|
+
const rawCode = readFileSync(args.path, 'utf8');
|
|
119
113
|
const loader = getLoader(args.path);
|
|
120
114
|
const transpiler = getTranspiler(loader);
|
|
121
115
|
const code = transpiler.transformSync(rawCode);
|
|
@@ -132,7 +126,7 @@ function wywInJS({ debug, include, exclude, filter = /\.[cm]?[jt]sx?$/, nodeModu
|
|
|
132
126
|
emitWarning,
|
|
133
127
|
eventEmitter: emitter,
|
|
134
128
|
};
|
|
135
|
-
const result = await
|
|
129
|
+
const result = await transform(transformServices, code, asyncResolve);
|
|
136
130
|
const { cssText } = result;
|
|
137
131
|
if (typeof cssText === 'undefined') {
|
|
138
132
|
return undefined;
|
|
@@ -148,8 +142,8 @@ function wywInJS({ debug, include, exclude, filter = /\.[cm]?[jt]sx?$/, nodeModu
|
|
|
148
142
|
loader,
|
|
149
143
|
};
|
|
150
144
|
}
|
|
151
|
-
const slug =
|
|
152
|
-
const cssFilename = `${args.path.replace(/\.[cm]?[jt]sx?$/, '')}_${slug}.wyw.css`.replace(/\\/g,
|
|
145
|
+
const slug = slugify(cssText);
|
|
146
|
+
const cssFilename = `${args.path.replace(/\.[cm]?[jt]sx?$/, '')}_${slug}.wyw.css`.replace(/\\/g, path.posix.sep);
|
|
153
147
|
let nextCssText = cssText;
|
|
154
148
|
let contents = `${result.code}\nimport ${JSON.stringify(cssFilename)};\n`;
|
|
155
149
|
if (sourceMap && result.cssSourceMapText) {
|
package/lib/index.js
DELETED
|
@@ -1,200 +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 = _interopRequireDefault(require("path"));
|
|
9
|
-
var _pluginutils = require("@rollup/pluginutils");
|
|
10
|
-
var _bun = require("bun");
|
|
11
|
-
var _shared = require("@wyw-in-js/shared");
|
|
12
|
-
var _transform = require("@wyw-in-js/transform");
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
|
|
15
|
-
function getLoader(filename) {
|
|
16
|
-
const ext = _path.default.extname(filename);
|
|
17
|
-
switch (ext) {
|
|
18
|
-
case '.jsx':
|
|
19
|
-
return 'jsx';
|
|
20
|
-
case '.ts':
|
|
21
|
-
case '.mts':
|
|
22
|
-
case '.cts':
|
|
23
|
-
return 'ts';
|
|
24
|
-
case '.tsx':
|
|
25
|
-
return 'tsx';
|
|
26
|
-
default:
|
|
27
|
-
return 'js';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function splitQueryAndHash(request) {
|
|
31
|
-
const queryIdx = request.indexOf('?');
|
|
32
|
-
const hashIdx = request.indexOf('#');
|
|
33
|
-
if (queryIdx === -1 && hashIdx === -1) {
|
|
34
|
-
return {
|
|
35
|
-
specifier: request,
|
|
36
|
-
suffix: ''
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
let startIdx;
|
|
40
|
-
if (queryIdx === -1) {
|
|
41
|
-
startIdx = hashIdx;
|
|
42
|
-
} else if (hashIdx === -1) {
|
|
43
|
-
startIdx = queryIdx;
|
|
44
|
-
} else {
|
|
45
|
-
startIdx = Math.min(queryIdx, hashIdx);
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
specifier: request.slice(0, startIdx),
|
|
49
|
-
suffix: request.slice(startIdx)
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function wywInJS({
|
|
53
|
-
debug,
|
|
54
|
-
include,
|
|
55
|
-
exclude,
|
|
56
|
-
filter = /\.[cm]?[jt]sx?$/,
|
|
57
|
-
nodeModules = false,
|
|
58
|
-
transformLibraries,
|
|
59
|
-
sourceMap,
|
|
60
|
-
keepComments,
|
|
61
|
-
prefixer,
|
|
62
|
-
preprocessor,
|
|
63
|
-
...rest
|
|
64
|
-
} = {}) {
|
|
65
|
-
const cache = new _transform.TransformCacheCollection();
|
|
66
|
-
const filterFn = (0, _pluginutils.createFilter)(include, exclude);
|
|
67
|
-
const allowNodeModules = transformLibraries !== null && transformLibraries !== void 0 ? transformLibraries : nodeModules;
|
|
68
|
-
return {
|
|
69
|
-
name: 'wyw-in-js',
|
|
70
|
-
setup(build) {
|
|
71
|
-
const cssLookup = new Map();
|
|
72
|
-
const emittedWarnings = new Set();
|
|
73
|
-
const {
|
|
74
|
-
emitter,
|
|
75
|
-
onDone
|
|
76
|
-
} = (0, _transform.createFileReporter)(debug !== null && debug !== void 0 ? debug : false);
|
|
77
|
-
const transpilers = new Map();
|
|
78
|
-
const getTranspiler = loader => {
|
|
79
|
-
const cached = transpilers.get(loader);
|
|
80
|
-
if (cached) {
|
|
81
|
-
return cached;
|
|
82
|
-
}
|
|
83
|
-
const created = new _bun.Transpiler({
|
|
84
|
-
loader,
|
|
85
|
-
autoImportJSX: true
|
|
86
|
-
});
|
|
87
|
-
transpilers.set(loader, created);
|
|
88
|
-
return created;
|
|
89
|
-
};
|
|
90
|
-
const asyncResolve = async (what, importer, stack) => {
|
|
91
|
-
const {
|
|
92
|
-
specifier,
|
|
93
|
-
suffix
|
|
94
|
-
} = splitQueryAndHash(what);
|
|
95
|
-
try {
|
|
96
|
-
return (await (0, _shared.asyncResolveFallback)(specifier, importer, stack)).replace(/\\/g, _path.default.posix.sep).concat(suffix);
|
|
97
|
-
} catch {
|
|
98
|
-
return (0, _bun.resolveSync)(specifier, importer).replace(/\\/g, _path.default.posix.sep).concat(suffix);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const emitWarning = message => {
|
|
102
|
-
var _match$;
|
|
103
|
-
const match = message.match(/\nconfig key: (.+)\n/);
|
|
104
|
-
const key = (_match$ = match === null || match === void 0 ? void 0 : match[1]) !== null && _match$ !== void 0 ? _match$ : message;
|
|
105
|
-
if (emittedWarnings.has(key)) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
emittedWarnings.add(key);
|
|
109
|
-
// eslint-disable-next-line no-console
|
|
110
|
-
console.warn(message);
|
|
111
|
-
};
|
|
112
|
-
build.onEnd(() => {
|
|
113
|
-
onDone(process.cwd());
|
|
114
|
-
});
|
|
115
|
-
build.onResolve({
|
|
116
|
-
filter: /\.wyw\.css$/
|
|
117
|
-
}, args => ({
|
|
118
|
-
namespace: 'wyw-in-js',
|
|
119
|
-
path: args.path
|
|
120
|
-
}));
|
|
121
|
-
build.onLoad({
|
|
122
|
-
filter: /.*/,
|
|
123
|
-
namespace: 'wyw-in-js'
|
|
124
|
-
}, async args => {
|
|
125
|
-
const contents = cssLookup.get(args.path);
|
|
126
|
-
if (typeof contents === 'undefined') {
|
|
127
|
-
return undefined;
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
contents,
|
|
131
|
-
loader: 'css'
|
|
132
|
-
};
|
|
133
|
-
});
|
|
134
|
-
const filterRegexp = typeof filter === 'string' ? new RegExp(filter) : filter;
|
|
135
|
-
build.onLoad({
|
|
136
|
-
filter: filterRegexp
|
|
137
|
-
}, async args => {
|
|
138
|
-
if (!filterFn(args.path)) {
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
if (!allowNodeModules && nodeModulesRegex.test(args.path)) {
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
const rawCode = (0, _fs.readFileSync)(args.path, 'utf8');
|
|
145
|
-
const loader = getLoader(args.path);
|
|
146
|
-
const transpiler = getTranspiler(loader);
|
|
147
|
-
const code = transpiler.transformSync(rawCode);
|
|
148
|
-
const transformServices = {
|
|
149
|
-
options: {
|
|
150
|
-
filename: args.path,
|
|
151
|
-
pluginOptions: rest,
|
|
152
|
-
prefixer,
|
|
153
|
-
keepComments,
|
|
154
|
-
preprocessor,
|
|
155
|
-
root: process.cwd()
|
|
156
|
-
},
|
|
157
|
-
cache,
|
|
158
|
-
emitWarning,
|
|
159
|
-
eventEmitter: emitter
|
|
160
|
-
};
|
|
161
|
-
const result = await (0, _transform.transform)(transformServices, code, asyncResolve);
|
|
162
|
-
const {
|
|
163
|
-
cssText
|
|
164
|
-
} = result;
|
|
165
|
-
if (typeof cssText === 'undefined') {
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
if (cssText === '') {
|
|
169
|
-
let contents = result.code;
|
|
170
|
-
if (sourceMap && result.sourceMap) {
|
|
171
|
-
const map = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
172
|
-
contents += `\n//# sourceMappingURL=data:application/json;base64,${map}`;
|
|
173
|
-
}
|
|
174
|
-
return {
|
|
175
|
-
contents,
|
|
176
|
-
loader
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
const slug = (0, _transform.slugify)(cssText);
|
|
180
|
-
const cssFilename = `${args.path.replace(/\.[cm]?[jt]sx?$/, '')}_${slug}.wyw.css`.replace(/\\/g, _path.default.posix.sep);
|
|
181
|
-
let nextCssText = cssText;
|
|
182
|
-
let contents = `${result.code}\nimport ${JSON.stringify(cssFilename)};\n`;
|
|
183
|
-
if (sourceMap && result.cssSourceMapText) {
|
|
184
|
-
const map = Buffer.from(result.cssSourceMapText).toString('base64');
|
|
185
|
-
nextCssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
|
|
186
|
-
}
|
|
187
|
-
if (sourceMap && result.sourceMap) {
|
|
188
|
-
const map = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
189
|
-
contents += `//# sourceMappingURL=data:application/json;base64,${map}\n`;
|
|
190
|
-
}
|
|
191
|
-
cssLookup.set(cssFilename, nextCssText);
|
|
192
|
-
return {
|
|
193
|
-
contents,
|
|
194
|
-
loader
|
|
195
|
-
};
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_fs","require","_path","_interopRequireDefault","_pluginutils","_bun","_shared","_transform","e","__esModule","default","nodeModulesRegex","getLoader","filename","ext","path","extname","splitQueryAndHash","request","queryIdx","indexOf","hashIdx","specifier","suffix","startIdx","Math","min","slice","wywInJS","debug","include","exclude","filter","nodeModules","transformLibraries","sourceMap","keepComments","prefixer","preprocessor","rest","cache","TransformCacheCollection","filterFn","createFilter","allowNodeModules","name","setup","build","cssLookup","Map","emittedWarnings","Set","emitter","onDone","createFileReporter","transpilers","getTranspiler","loader","cached","get","created","Transpiler","autoImportJSX","set","asyncResolve","what","importer","stack","asyncResolveFallback","replace","posix","sep","concat","resolveSync","emitWarning","message","_match$","match","key","has","add","console","warn","onEnd","process","cwd","onResolve","args","namespace","onLoad","contents","undefined","filterRegexp","RegExp","test","rawCode","readFileSync","transpiler","code","transformSync","transformServices","options","pluginOptions","root","eventEmitter","result","transform","cssText","map","Buffer","from","JSON","stringify","toString","slug","slugify","cssFilename","nextCssText","cssSourceMapText"],"sources":["../src/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport path from 'path';\n\nimport { createFilter } from '@rollup/pluginutils';\nimport type { FilterPattern } from '@rollup/pluginutils';\nimport type { BunPlugin, JavaScriptLoader, PluginBuilder } from 'bun';\nimport { resolveSync, Transpiler } from 'bun';\n\nimport { asyncResolveFallback } from '@wyw-in-js/shared';\nimport type {\n IFileReporterOptions,\n PluginOptions,\n Preprocessor,\n} from '@wyw-in-js/transform';\nimport {\n createFileReporter,\n slugify,\n transform,\n TransformCacheCollection,\n} from '@wyw-in-js/transform';\n\nexport type BunPluginOptions = {\n debug?: IFileReporterOptions | false | null | undefined;\n exclude?: FilterPattern;\n filter?: RegExp | string;\n include?: FilterPattern;\n keepComments?: boolean | RegExp;\n nodeModules?: boolean;\n prefixer?: boolean;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n transformLibraries?: boolean;\n} & Partial<PluginOptions>;\n\nconst nodeModulesRegex = /^(?:.*[\\\\/])?node_modules(?:[\\\\/].*)?$/;\n\nfunction getLoader(filename: string): JavaScriptLoader {\n const ext = path.extname(filename);\n switch (ext) {\n case '.jsx':\n return 'jsx';\n case '.ts':\n case '.mts':\n case '.cts':\n return 'ts';\n case '.tsx':\n return 'tsx';\n default:\n return 'js';\n }\n}\n\nfunction splitQueryAndHash(request: string): {\n specifier: string;\n suffix: string;\n} {\n const queryIdx = request.indexOf('?');\n const hashIdx = request.indexOf('#');\n\n if (queryIdx === -1 && hashIdx === -1) {\n return { specifier: request, suffix: '' };\n }\n\n let startIdx: number;\n if (queryIdx === -1) {\n startIdx = hashIdx;\n } else if (hashIdx === -1) {\n startIdx = queryIdx;\n } else {\n startIdx = Math.min(queryIdx, hashIdx);\n }\n\n return {\n specifier: request.slice(0, startIdx),\n suffix: request.slice(startIdx),\n };\n}\n\nexport default function wywInJS({\n debug,\n include,\n exclude,\n filter = /\\.[cm]?[jt]sx?$/,\n nodeModules = false,\n transformLibraries,\n sourceMap,\n keepComments,\n prefixer,\n preprocessor,\n ...rest\n}: BunPluginOptions = {}): BunPlugin {\n const cache = new TransformCacheCollection();\n const filterFn = createFilter(include, exclude);\n const allowNodeModules = transformLibraries ?? nodeModules;\n\n return {\n name: 'wyw-in-js',\n setup(build: PluginBuilder) {\n const cssLookup = new Map<string, string>();\n const emittedWarnings = new Set<string>();\n\n const { emitter, onDone } = createFileReporter(debug ?? false);\n\n const transpilers = new Map<\n JavaScriptLoader,\n InstanceType<typeof Transpiler>\n >();\n const getTranspiler = (\n loader: JavaScriptLoader\n ): InstanceType<typeof Transpiler> => {\n const cached = transpilers.get(loader);\n if (cached) {\n return cached;\n }\n\n const created = new Transpiler({ loader, autoImportJSX: true });\n transpilers.set(loader, created);\n return created;\n };\n\n const asyncResolve = async (\n what: string,\n importer: string,\n stack: string[]\n ): Promise<string | null> => {\n const { specifier, suffix } = splitQueryAndHash(what);\n try {\n return (await asyncResolveFallback(specifier, importer, stack))\n .replace(/\\\\/g, path.posix.sep)\n .concat(suffix);\n } catch {\n return resolveSync(specifier, importer)\n .replace(/\\\\/g, path.posix.sep)\n .concat(suffix);\n }\n };\n\n const emitWarning = (message: string) => {\n const match = message.match(/\\nconfig key: (.+)\\n/);\n const key = match?.[1] ?? message;\n if (emittedWarnings.has(key)) {\n return;\n }\n\n emittedWarnings.add(key);\n // eslint-disable-next-line no-console\n console.warn(message);\n };\n\n build.onEnd(() => {\n onDone(process.cwd());\n });\n\n build.onResolve({ filter: /\\.wyw\\.css$/ }, (args) => ({\n namespace: 'wyw-in-js',\n path: args.path,\n }));\n\n build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, async (args) => {\n const contents = cssLookup.get(args.path);\n if (typeof contents === 'undefined') {\n return undefined;\n }\n\n return {\n contents,\n loader: 'css',\n };\n });\n\n const filterRegexp =\n typeof filter === 'string' ? new RegExp(filter) : filter;\n\n build.onLoad({ filter: filterRegexp }, async (args) => {\n if (!filterFn(args.path)) {\n return undefined;\n }\n\n if (!allowNodeModules && nodeModulesRegex.test(args.path)) {\n return undefined;\n }\n\n const rawCode = readFileSync(args.path, 'utf8');\n const loader = getLoader(args.path);\n const transpiler = getTranspiler(loader);\n\n const code = transpiler.transformSync(rawCode);\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 emitWarning,\n eventEmitter: emitter,\n };\n\n const result = await transform(transformServices, code, asyncResolve);\n\n const { cssText } = result;\n\n if (typeof cssText === 'undefined') {\n return undefined;\n }\n\n if (cssText === '') {\n let contents = result.code;\n\n if (sourceMap && result.sourceMap) {\n const map = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `\\n//# sourceMappingURL=data:application/json;base64,${map}`;\n }\n\n return {\n contents,\n loader,\n };\n }\n\n const slug = slugify(cssText);\n const cssFilename = `${args.path.replace(\n /\\.[cm]?[jt]sx?$/,\n ''\n )}_${slug}.wyw.css`.replace(/\\\\/g, path.posix.sep);\n\n let nextCssText = cssText;\n let contents = `${result.code}\\nimport ${JSON.stringify(\n cssFilename\n )};\\n`;\n\n if (sourceMap && result.cssSourceMapText) {\n const map = Buffer.from(result.cssSourceMapText).toString('base64');\n nextCssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;\n }\n\n if (sourceMap && result.sourceMap) {\n const map = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `//# sourceMappingURL=data:application/json;base64,${map}\\n`;\n }\n\n cssLookup.set(cssFilename, nextCssText);\n\n return {\n contents,\n loader,\n };\n });\n },\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAGA,IAAAI,IAAA,GAAAJ,OAAA;AAEA,IAAAK,OAAA,GAAAL,OAAA;AAMA,IAAAM,UAAA,GAAAN,OAAA;AAK8B,SAAAE,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAe9B,MAAMG,gBAAgB,GAAG,wCAAwC;AAEjE,SAASC,SAASA,CAACC,QAAgB,EAAoB;EACrD,MAAMC,GAAG,GAAGC,aAAI,CAACC,OAAO,CAACH,QAAQ,CAAC;EAClC,QAAQC,GAAG;IACT,KAAK,MAAM;MACT,OAAO,KAAK;IACd,KAAK,KAAK;IACV,KAAK,MAAM;IACX,KAAK,MAAM;MACT,OAAO,IAAI;IACb,KAAK,MAAM;MACT,OAAO,KAAK;IACd;MACE,OAAO,IAAI;EACf;AACF;AAEA,SAASG,iBAAiBA,CAACC,OAAe,EAGxC;EACA,MAAMC,QAAQ,GAAGD,OAAO,CAACE,OAAO,CAAC,GAAG,CAAC;EACrC,MAAMC,OAAO,GAAGH,OAAO,CAACE,OAAO,CAAC,GAAG,CAAC;EAEpC,IAAID,QAAQ,KAAK,CAAC,CAAC,IAAIE,OAAO,KAAK,CAAC,CAAC,EAAE;IACrC,OAAO;MAAEC,SAAS,EAAEJ,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