@wyw-in-js/turbopack-loader 1.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-modules.js","names":["nestingAtRules","Set","isWhitespace","char","isKeyframesAtRule","name","toLowerCase","endsWith","readString","css","start","quote","idx","length","readComment","end","indexOf","findAtRuleTerminator","parenDepth","bracketDepth","findMatchingBrace","openBraceIdx","depth","splitSelectorList","selectorText","parts","push","slice","wrapSelector","selectors","map","s","trim","filter","Boolean","selector","join","wrapKeyframesHeader","prelude","startsWith","match","exec","before","after","makeCssModuleGlobalInner","out","nameStart","nameEnd","test","atRuleName","terminatorIdx","terminator","blockEndIdx","blockBody","has","openIdx","makeCssModuleGlobal","cssText"],"sources":["../src/css-modules.ts"],"sourcesContent":["const nestingAtRules = new Set([\n 'container',\n 'document',\n 'layer',\n 'media',\n 'scope',\n 'starting-style',\n 'supports',\n]);\n\nfunction isWhitespace(char: string) {\n return (\n char === ' ' ||\n char === '\\n' ||\n char === '\\r' ||\n char === '\\t' ||\n char === '\\f'\n );\n}\n\nfunction isKeyframesAtRule(name: string) {\n return name.toLowerCase().endsWith('keyframes');\n}\n\nfunction readString(css: string, start: number) {\n const quote = css[start];\n let idx = start + 1;\n\n while (idx < css.length) {\n const char = css[idx];\n\n if (char === '\\\\') {\n idx += 2;\n } else if (char === quote) {\n return idx + 1;\n } else {\n idx += 1;\n }\n }\n\n return css.length;\n}\n\nfunction readComment(css: string, start: number) {\n const end = css.indexOf('*/', start + 2);\n return end === -1 ? css.length : end + 2;\n}\n\nfunction findAtRuleTerminator(css: string, start: number) {\n let idx = start;\n let parenDepth = 0;\n let bracketDepth = 0;\n\n while (idx < css.length) {\n const char = css[idx];\n\n if (char === '/' && css[idx + 1] === '*') {\n idx = readComment(css, idx);\n } else if (char === '\"' || char === \"'\") {\n idx = readString(css, idx);\n } else {\n if (char === '(') parenDepth += 1;\n else if (char === ')' && parenDepth > 0) parenDepth -= 1;\n else if (char === '[') bracketDepth += 1;\n else if (char === ']' && bracketDepth > 0) bracketDepth -= 1;\n\n if (\n parenDepth === 0 &&\n bracketDepth === 0 &&\n (char === ';' || char === '{')\n ) {\n return idx;\n }\n\n idx += 1;\n }\n }\n\n return css.length;\n}\n\nfunction findMatchingBrace(css: string, openBraceIdx: number) {\n let idx = openBraceIdx + 1;\n let depth = 1;\n\n while (idx < css.length) {\n const char = css[idx];\n\n if (char === '/' && css[idx + 1] === '*') {\n idx = readComment(css, idx);\n } else if (char === '\"' || char === \"'\") {\n idx = readString(css, idx);\n } else {\n if (char === '{') depth += 1;\n else if (char === '}') {\n depth -= 1;\n if (depth === 0) return idx;\n }\n\n idx += 1;\n }\n }\n\n return -1;\n}\n\nfunction splitSelectorList(selectorText: string) {\n const parts: string[] = [];\n let start = 0;\n let idx = 0;\n let parenDepth = 0;\n let bracketDepth = 0;\n\n while (idx < selectorText.length) {\n const char = selectorText[idx];\n\n if (char === '/' && selectorText[idx + 1] === '*') {\n idx = readComment(selectorText, idx);\n } else if (char === '\"' || char === \"'\") {\n idx = readString(selectorText, idx);\n } else {\n if (char === '(') parenDepth += 1;\n else if (char === ')' && parenDepth > 0) parenDepth -= 1;\n else if (char === '[') bracketDepth += 1;\n else if (char === ']' && bracketDepth > 0) bracketDepth -= 1;\n\n if (parenDepth === 0 && bracketDepth === 0 && char === ',') {\n parts.push(selectorText.slice(start, idx));\n start = idx + 1;\n }\n\n idx += 1;\n }\n }\n\n parts.push(selectorText.slice(start));\n\n return parts;\n}\n\nfunction wrapSelector(selectorText: string) {\n const selectors = splitSelectorList(selectorText)\n .map((s) => s.trim())\n .filter(Boolean);\n\n return selectors.map((selector) => `:global(${selector})`).join(', ');\n}\n\nfunction wrapKeyframesHeader(prelude: string) {\n let idx = 0;\n while (idx < prelude.length && isWhitespace(prelude[idx])) idx += 1;\n\n if (prelude.slice(idx).startsWith(':global(')) {\n return prelude;\n }\n\n const match = /^[A-Za-z_-][A-Za-z0-9_-]*/.exec(prelude.slice(idx));\n if (!match) return prelude;\n\n const name = match[0];\n const before = prelude.slice(0, idx);\n const after = prelude.slice(idx + name.length);\n return `${before}:global(${name})${after}`;\n}\n\nfunction makeCssModuleGlobalInner(css: string) {\n let idx = 0;\n let out = '';\n\n while (idx < css.length) {\n const char = css[idx];\n\n if (isWhitespace(char)) {\n out += char;\n idx += 1;\n } else if (char === '/' && css[idx + 1] === '*') {\n const end = readComment(css, idx);\n out += css.slice(idx, end);\n idx = end;\n } else if (char === '\"' || char === \"'\") {\n const end = readString(css, idx);\n out += css.slice(idx, end);\n idx = end;\n } else if (char === '@') {\n const nameStart = idx + 1;\n let nameEnd = nameStart;\n while (nameEnd < css.length && /[A-Za-z0-9_-]/.test(css[nameEnd])) {\n nameEnd += 1;\n }\n const atRuleName = css.slice(nameStart, nameEnd);\n const terminatorIdx = findAtRuleTerminator(css, nameEnd);\n const terminator = css[terminatorIdx];\n const prelude = css.slice(nameEnd, terminatorIdx);\n\n if (terminator === ';') {\n out += css.slice(idx, terminatorIdx + 1);\n idx = terminatorIdx + 1;\n } else if (terminator !== '{') {\n out += css.slice(idx);\n break;\n } else {\n const blockEndIdx = findMatchingBrace(css, terminatorIdx);\n if (blockEndIdx === -1) {\n out += css.slice(idx);\n break;\n }\n\n const blockBody = css.slice(terminatorIdx + 1, blockEndIdx);\n\n if (isKeyframesAtRule(atRuleName)) {\n out += `@${atRuleName}${wrapKeyframesHeader(prelude)}{${blockBody}}`;\n } else if (nestingAtRules.has(atRuleName.toLowerCase())) {\n out += `@${atRuleName}${prelude}{${makeCssModuleGlobalInner(\n blockBody\n )}}`;\n } else {\n out += `@${atRuleName}${prelude}{${blockBody}}`;\n }\n\n idx = blockEndIdx + 1;\n }\n } else {\n // A selector rule: read until '{' at top-level.\n const openIdx = css.indexOf('{', idx);\n if (openIdx === -1) {\n out += css.slice(idx);\n break;\n }\n\n const selectorText = css.slice(idx, openIdx).trim();\n const blockEndIdx = findMatchingBrace(css, openIdx);\n if (blockEndIdx === -1) {\n out += css.slice(idx);\n break;\n }\n\n const blockBody = css.slice(openIdx + 1, blockEndIdx);\n out += `${wrapSelector(selectorText)}{${blockBody}}`;\n idx = blockEndIdx + 1;\n }\n }\n\n return out;\n}\n\nexport function makeCssModuleGlobal(cssText: string) {\n return makeCssModuleGlobalInner(cssText);\n}\n"],"mappings":";;;;;;AAAA,MAAMA,cAAc,GAAG,IAAIC,GAAG,CAAC,CAC7B,WAAW,EACX,UAAU,EACV,OAAO,EACP,OAAO,EACP,OAAO,EACP,gBAAgB,EAChB,UAAU,CACX,CAAC;AAEF,SAASC,YAAYA,CAACC,IAAY,EAAE;EAClC,OACEA,IAAI,KAAK,GAAG,IACZA,IAAI,KAAK,IAAI,IACbA,IAAI,KAAK,IAAI,IACbA,IAAI,KAAK,IAAI,IACbA,IAAI,KAAK,IAAI;AAEjB;AAEA,SAASC,iBAAiBA,CAACC,IAAY,EAAE;EACvC,OAAOA,IAAI,CAACC,WAAW,CAAC,CAAC,CAACC,QAAQ,CAAC,WAAW,CAAC;AACjD;AAEA,SAASC,UAAUA,CAACC,GAAW,EAAEC,KAAa,EAAE;EAC9C,MAAMC,KAAK,GAAGF,GAAG,CAACC,KAAK,CAAC;EACxB,IAAIE,GAAG,GAAGF,KAAK,GAAG,CAAC;EAEnB,OAAOE,GAAG,GAAGH,GAAG,CAACI,MAAM,EAAE;IACvB,MAAMV,IAAI,GAAGM,GAAG,CAACG,GAAG,CAAC;IAErB,IAAIT,IAAI,KAAK,IAAI,EAAE;MACjBS,GAAG,IAAI,CAAC;IACV,CAAC,MAAM,IAAIT,IAAI,KAAKQ,KAAK,EAAE;MACzB,OAAOC,GAAG,GAAG,CAAC;IAChB,CAAC,MAAM;MACLA,GAAG,IAAI,CAAC;IACV;EACF;EAEA,OAAOH,GAAG,CAACI,MAAM;AACnB;AAEA,SAASC,WAAWA,CAACL,GAAW,EAAEC,KAAa,EAAE;EAC/C,MAAMK,GAAG,GAAGN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DzC,GAAG,GAAGwC,WAAW,GAAG,CAAC;IACvB;EACF;EAEA,OAAOP,GAAG;AACZ;AAEO,SAASW,mBAAmBA,CAACC,OAAe,EAAE;EACnD,OAAOb,wBAAwB,CAACa,OAAO,CAAC;AAC1C","ignoreList":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.writeFileIfChanged = writeFileIfChanged;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function writeFileIfChanged(filePath, content) {
11
+ let previous = null;
12
+ try {
13
+ previous = _fs.default.readFileSync(filePath, 'utf8');
14
+ } catch (err) {
15
+ if (err.code !== 'ENOENT') {
16
+ throw err;
17
+ }
18
+ }
19
+ if (previous === content) {
20
+ return false;
21
+ }
22
+ const dir = _path.default.dirname(filePath);
23
+ const tmpPath = _path.default.join(dir, `${_path.default.basename(filePath)}.${process.pid}.${Date.now()}.tmp`);
24
+ try {
25
+ _fs.default.writeFileSync(tmpPath, content);
26
+ _fs.default.renameSync(tmpPath, filePath);
27
+ } finally {
28
+ try {
29
+ _fs.default.unlinkSync(tmpPath);
30
+ } catch {
31
+ // ignore
32
+ }
33
+ }
34
+ return true;
35
+ }
36
+ //# sourceMappingURL=file-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-utils.js","names":["_fs","_interopRequireDefault","require","_path","e","__esModule","default","writeFileIfChanged","filePath","content","previous","fs","readFileSync","err","code","dir","path","dirname","tmpPath","join","basename","process","pid","Date","now","writeFileSync","renameSync","unlinkSync"],"sources":["../src/file-utils.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nexport function writeFileIfChanged(filePath: string, content: string) {\n let previous: string | null = null;\n\n try {\n previous = fs.readFileSync(filePath, 'utf8');\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n throw err;\n }\n }\n\n if (previous === content) {\n return false;\n }\n\n const dir = path.dirname(filePath);\n const tmpPath = path.join(\n dir,\n `${path.basename(filePath)}.${process.pid}.${Date.now()}.tmp`\n );\n\n try {\n fs.writeFileSync(tmpPath, content);\n fs.renameSync(tmpPath, filePath);\n } finally {\n try {\n fs.unlinkSync(tmpPath);\n } catch {\n // ignore\n }\n }\n\n return true;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAwB,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEjB,SAASG,kBAAkBA,CAACC,QAAgB,EAAEC,OAAe,EAAE;EACpE,IAAIC,QAAuB,GAAG,IAAI;EAElC,IAAI;IACFA,QAAQ,GAAGC,WAAE,CAACC,YAAY,CAACJ,QAAQ,EAAE,MAAM,CAAC;EAC9C,CAAC,CAAC,OAAOK,GAAG,EAAE;IACZ,IAAKA,GAAG,CAA2BC,IAAI,KAAK,QAAQ,EAAE;MACpD,MAAMD,GAAG;IACX;EACF;EAEA,IAAIH,QAAQ,KAAKD,OAAO,EAAE;IACxB,OAAO,KAAK;EACd;EAEA,MAAMM,GAAG,GAAGC,aAAI,CAACC,OAAO,CAACT,QAAQ,CAAC;EAClC,MAAMU,OAAO,GAAGF,aAAI,CAACG,IAAI,CACvBJ,GAAG,EACH,GAAGC,aAAI,CAACI,QAAQ,CAACZ,QAAQ,CAAC,IAAIa,OAAO,CAACC,GAAG,IAAIC,IAAI,CAACC,GAAG,CAAC,CAAC,MACzD,CAAC;EAED,IAAI;IACFb,WAAE,CAACc,aAAa,CAACP,OAAO,EAAET,OAAO,CAAC;IAClCE,WAAE,CAACe,UAAU,CAACR,OAAO,EAAEV,QAAQ,CAAC;EAClC,CAAC,SAAS;IACR,IAAI;MACFG,WAAE,CAACgB,UAAU,CAACT,OAAO,CAAC;IACxB,CAAC,CAAC,MAAM;MACN;IAAA;EAEJ;EAEA,OAAO,IAAI;AACb","ignoreList":[]}
package/lib/index.js ADDED
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _shared = require("@wyw-in-js/shared");
10
+ var _transform = require("@wyw-in-js/transform");
11
+ var _cssModules = require("./css-modules");
12
+ var _fileUtils = require("./file-utils");
13
+ var _insertImport = require("./insert-import");
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ const DEFAULT_EXTENSION = '.wyw-in-js.module.css';
16
+ const stripQueryAndHash = request => {
17
+ const queryIdx = request.indexOf('?');
18
+ const hashIdx = request.indexOf('#');
19
+ if (queryIdx === -1) {
20
+ return hashIdx === -1 ? request : request.slice(0, hashIdx);
21
+ }
22
+ if (hashIdx === -1) return request.slice(0, queryIdx);
23
+ return request.slice(0, Math.min(queryIdx, hashIdx));
24
+ };
25
+ const cache = new _transform.TransformCacheCollection();
26
+ function convertSourceMap(value, filename) {
27
+ var _value$file, _value$mappings, _value$names, _value$sources, _value$version;
28
+ if (typeof value === 'string' || !value) {
29
+ return undefined;
30
+ }
31
+ return {
32
+ ...value,
33
+ file: (_value$file = value.file) !== null && _value$file !== void 0 ? _value$file : filename,
34
+ mappings: (_value$mappings = value.mappings) !== null && _value$mappings !== void 0 ? _value$mappings : '',
35
+ names: (_value$names = value.names) !== null && _value$names !== void 0 ? _value$names : [],
36
+ sources: (_value$sources = value.sources) !== null && _value$sources !== void 0 ? _value$sources : [],
37
+ version: (_value$version = value.version) !== null && _value$version !== void 0 ? _value$version : 3
38
+ };
39
+ }
40
+ async function resolveWith(resolve, context, request) {
41
+ if (typeof resolve !== 'function') return false;
42
+ if (resolve.length >= 3) {
43
+ return new Promise((ok, fail) => {
44
+ resolve(context, request, (err, result) => {
45
+ if (err) fail(err);else ok(result !== null && result !== void 0 ? result : false);
46
+ });
47
+ });
48
+ }
49
+ return resolve(context, request);
50
+ }
51
+ const turbopackLoader = function turbopackLoader(content, inputSourceMap) {
52
+ const callbackFromAsync = typeof this.async === 'function' ? this.async() : undefined;
53
+ const callback = typeof callbackFromAsync === 'function' ? callbackFromAsync : this.callback;
54
+ if (typeof callback !== 'function') {
55
+ throw new Error('Async loader callback is not available');
56
+ }
57
+ (0, _shared.logger)('turbopack-loader %s', this.resourcePath);
58
+ const {
59
+ sourceMap,
60
+ keepComments,
61
+ prefixer,
62
+ configFile,
63
+ ...rest
64
+ } = this.getOptions() || {};
65
+ if (configFile) {
66
+ const configPath = _path.default.isAbsolute(configFile) ? configFile : _path.default.join(process.cwd(), configFile);
67
+ this.addDependency(configPath);
68
+ }
69
+ const cssFileName = `${_path.default.basename(this.resourcePath, _path.default.extname(this.resourcePath))}${DEFAULT_EXTENSION}`;
70
+ const cssFilePath = _path.default.join(_path.default.dirname(this.resourcePath), cssFileName);
71
+ const cssImportPath = `./${cssFileName}`;
72
+ const resolveModule = this.getResolve({
73
+ dependencyType: 'esm'
74
+ });
75
+ const asyncResolve = async (token, importer) => {
76
+ const context = _path.default.isAbsolute(importer) ? _path.default.dirname(importer) : _path.default.join(process.cwd(), _path.default.dirname(importer));
77
+ const result = await resolveWith(resolveModule, context, token);
78
+ if (!result) {
79
+ throw new Error(`Cannot resolve ${token} from ${context}`);
80
+ }
81
+ const filePath = stripQueryAndHash(result);
82
+ if (_path.default.isAbsolute(filePath)) {
83
+ this.addDependency(filePath);
84
+ }
85
+ return result;
86
+ };
87
+ const transformServices = {
88
+ options: {
89
+ filename: this.resourcePath,
90
+ inputSourceMap: convertSourceMap(inputSourceMap, this.resourcePath),
91
+ pluginOptions: {
92
+ configFile,
93
+ ...rest
94
+ },
95
+ prefixer,
96
+ keepComments,
97
+ root: process.cwd()
98
+ },
99
+ cache,
100
+ emitWarning: message => {
101
+ if (typeof this.emitWarning === 'function') {
102
+ this.emitWarning(new Error(message));
103
+ }
104
+ }
105
+ };
106
+ (0, _transform.transform)(transformServices, content.toString(), asyncResolve).then(async result => {
107
+ var _result$cssText, _result$sourceMap2;
108
+ const rawCssText = (_result$cssText = result.cssText) !== null && _result$cssText !== void 0 ? _result$cssText : '';
109
+ if (rawCssText.trim()) {
110
+ var _result$dependencies, _result$sourceMap;
111
+ let cssText = (0, _cssModules.makeCssModuleGlobal)(rawCssText);
112
+ if (sourceMap && typeof result.cssSourceMapText !== 'undefined') {
113
+ cssText += `\n/*# sourceMappingURL=data:application/json;base64,${Buffer.from(result.cssSourceMapText).toString('base64')}*/\n`;
114
+ }
115
+ await Promise.all(((_result$dependencies = result.dependencies) !== null && _result$dependencies !== void 0 ? _result$dependencies : []).map(dep => asyncResolve(dep, this.resourcePath)));
116
+ (0, _fileUtils.writeFileIfChanged)(cssFilePath, cssText);
117
+ const importStatement = `import ${JSON.stringify(cssImportPath)};`;
118
+ const finalCode = (0, _insertImport.insertImportStatement)(result.code, importStatement);
119
+ callback(null, finalCode, (_result$sourceMap = result.sourceMap) !== null && _result$sourceMap !== void 0 ? _result$sourceMap : undefined);
120
+ return;
121
+ }
122
+ if (_fs.default.existsSync(cssFilePath)) {
123
+ (0, _fileUtils.writeFileIfChanged)(cssFilePath, '');
124
+ }
125
+ callback(null, result.code, (_result$sourceMap2 = result.sourceMap) !== null && _result$sourceMap2 !== void 0 ? _result$sourceMap2 : undefined);
126
+ }).catch(err => callback(err));
127
+ };
128
+ var _default = exports.default = turbopackLoader;
129
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_fs","_interopRequireDefault","require","_path","_shared","_transform","_cssModules","_fileUtils","_insertImport","e","__esModule","default","DEFAULT_EXTENSION","stripQueryAndHash","request","queryIdx","indexOf","hashIdx","slice","Math","min","cache","TransformCacheCollection","convertSourceMap","value","filename","_value$file","_value$mappings","_value$names","_value$sources","_value$version","undefined","file","mappings","names","sources","version","resolveWith","resolve","context","length","Promise","ok","fail","err","result","turbopackLoader","content","inputSourceMap","callbackFromAsync","async","callback","Error","logger","resourcePath","sourceMap","keepComments","prefixer","configFile","rest","getOptions","configPath","path","isAbsolute","join","process","cwd","addDependency","cssFileName","basename","extname","cssFilePath","dirname","cssImportPath","resolveModule","getResolve","dependencyType","asyncResolve","token","importer","filePath","transformServices","options","pluginOptions","root","emitWarning","message","transform","toString","then","_result$cssText","_result$sourceMap2","rawCssText","cssText","trim","_result$dependencies","_result$sourceMap","makeCssModuleGlobal","cssSourceMapText","Buffer","from","all","dependencies","map","dep","writeFileIfChanged","importStatement","JSON","stringify","finalCode","insertImportStatement","code","fs","existsSync","catch","_default","exports"],"sources":["../src/index.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nimport type { RawSourceMap } from 'source-map';\nimport type { LoaderContext, RawLoaderDefinitionFunction } from 'webpack';\n\nimport { logger } from '@wyw-in-js/shared';\nimport type { PluginOptions, Result } from '@wyw-in-js/transform';\nimport { transform, TransformCacheCollection } from '@wyw-in-js/transform';\n\nimport { makeCssModuleGlobal } from './css-modules';\nimport { writeFileIfChanged } from './file-utils';\nimport { insertImportStatement } from './insert-import';\n\nconst DEFAULT_EXTENSION = '.wyw-in-js.module.css';\n\nconst stripQueryAndHash = (request: string) => {\n const queryIdx = request.indexOf('?');\n const hashIdx = request.indexOf('#');\n\n if (queryIdx === -1) {\n return hashIdx === -1 ? request : request.slice(0, hashIdx);\n }\n if (hashIdx === -1) return request.slice(0, queryIdx);\n\n return request.slice(0, Math.min(queryIdx, hashIdx));\n};\n\nexport type LoaderOptions = {\n keepComments?: boolean;\n prefixer?: boolean;\n sourceMap?: boolean;\n} & Partial<PluginOptions>;\n\ntype Loader = RawLoaderDefinitionFunction<LoaderOptions>;\ntype ResolveFn = ReturnType<LoaderContext<LoaderOptions>['getResolve']>;\n\nconst cache = new TransformCacheCollection();\n\nfunction convertSourceMap(\n value: RawSourceMap | string | null | undefined,\n filename: string\n): RawSourceMap | undefined {\n if (typeof value === 'string' || !value) {\n return undefined;\n }\n\n return {\n ...value,\n file: value.file ?? filename,\n mappings: value.mappings ?? '',\n names: value.names ?? [],\n sources: value.sources ?? [],\n version: value.version ?? 3,\n };\n}\n\nasync function resolveWith(\n resolve: ResolveFn,\n context: string,\n request: string\n): Promise<string | false> {\n type ResolveCallback = (\n ctx: string,\n req: string,\n cb: (err: Error | null, result?: string) => void\n ) => void;\n type ResolveAsync = (ctx: string, req: string) => Promise<string | false>;\n\n if (typeof resolve !== 'function') return false;\n\n if (resolve.length >= 3) {\n return new Promise((ok, fail) => {\n (resolve as unknown as ResolveCallback)(\n context,\n request,\n (err, result) => {\n if (err) fail(err);\n else ok(result ?? false);\n }\n );\n });\n }\n\n return (resolve as unknown as ResolveAsync)(context, request);\n}\n\nconst turbopackLoader: Loader = function turbopackLoader(\n content,\n inputSourceMap\n) {\n const callbackFromAsync =\n typeof this.async === 'function' ? this.async() : undefined;\n const callback =\n typeof callbackFromAsync === 'function' ? callbackFromAsync : this.callback;\n\n if (typeof callback !== 'function') {\n throw new Error('Async loader callback is not available');\n }\n\n logger('turbopack-loader %s', this.resourcePath);\n\n const { sourceMap, keepComments, prefixer, configFile, ...rest } =\n this.getOptions() || {};\n\n if (configFile) {\n const configPath = path.isAbsolute(configFile)\n ? configFile\n : path.join(process.cwd(), configFile);\n this.addDependency(configPath);\n }\n\n const cssFileName = `${path.basename(\n this.resourcePath,\n path.extname(this.resourcePath)\n )}${DEFAULT_EXTENSION}`;\n const cssFilePath = path.join(path.dirname(this.resourcePath), cssFileName);\n const cssImportPath = `./${cssFileName}`;\n\n const resolveModule = this.getResolve({ dependencyType: 'esm' });\n\n const asyncResolve = async (token: string, importer: string) => {\n const context = path.isAbsolute(importer)\n ? path.dirname(importer)\n : path.join(process.cwd(), path.dirname(importer));\n\n const result = await resolveWith(resolveModule, context, token);\n\n if (!result) {\n throw new Error(`Cannot resolve ${token} from ${context}`);\n }\n\n const filePath = stripQueryAndHash(result);\n if (path.isAbsolute(filePath)) {\n this.addDependency(filePath);\n }\n\n return result;\n };\n\n const transformServices = {\n options: {\n filename: this.resourcePath,\n inputSourceMap: convertSourceMap(inputSourceMap, this.resourcePath),\n pluginOptions: { configFile, ...rest },\n prefixer,\n keepComments,\n root: process.cwd(),\n },\n cache,\n emitWarning: (message: string) => {\n if (typeof this.emitWarning === 'function') {\n this.emitWarning(new Error(message));\n }\n },\n };\n\n transform(transformServices, content.toString(), asyncResolve)\n .then(async (result: Result) => {\n const rawCssText = result.cssText ?? '';\n\n if (rawCssText.trim()) {\n let cssText = makeCssModuleGlobal(rawCssText);\n\n if (sourceMap && typeof result.cssSourceMapText !== 'undefined') {\n cssText += `\\n/*# sourceMappingURL=data:application/json;base64,${Buffer.from(\n result.cssSourceMapText\n ).toString('base64')}*/\\n`;\n }\n\n await Promise.all(\n (result.dependencies ?? []).map((dep) =>\n asyncResolve(dep, this.resourcePath)\n )\n );\n\n writeFileIfChanged(cssFilePath, cssText);\n\n const importStatement = `import ${JSON.stringify(cssImportPath)};`;\n const finalCode = insertImportStatement(result.code, importStatement);\n\n callback(null, finalCode, result.sourceMap ?? undefined);\n return;\n }\n\n if (fs.existsSync(cssFilePath)) {\n writeFileIfChanged(cssFilePath, '');\n }\n\n callback(null, result.code, result.sourceMap ?? undefined);\n })\n .catch((err: Error) => callback(err));\n};\n\nexport default turbopackLoader;\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAKA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AAEA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AAAwD,SAAAD,uBAAAQ,CAAA,WAAAA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ACC,IAAI,CAC3EvD,MAAM,CAACqD,gBACT,CAAC,CAACV,QAAQ,CAAC,QAAQ,CAAC,MAAM;MAC5B;MAEA,MAAM/C,OAAO,CAAC4D,GAAG,CACf,EAAAN,oBAAA,GAAClD,MAAM,CAACyD,YAAY,cAAAP,oBAAA,cAAAA,oBAAA,GAAI,EAAE,EAAEQ,GAAG,CAAEC,GAAG,IAClC3B,YAAY,CAAC2B,GAAG,EAAE,IAAI,CAAClD,YAAY,CACrC,CACF,CAAC;MAED,IAAAmD,6BAAkB,EAAClC,WAAW,EAAEsB,OAAO,CAAC;MAExC,MAAMa,eAAe,GAAG,UAAUC,IAAI,CAACC,SAAS,CAACnC,aAAa,CAAC,GAAG;MAClE,MAAMoC,SAAS,GAAG,IAAAC,mCAAqB,EAACjE,MAAM,CAACkE,IAAI,EAAEL,eAAe,CAAC;MAErEvD,QAAQ,CAAC,IAAI,EAAE0D,SAAS,GAAAb,iBAAA,GAAEnD,MAAM,CAACU,SAAS,cAAAyC,iBAAA,cAAAA,iBAAA,GAAIjE,SAAS,CAAC;MACxD;IACF;IAEA,IAAIiF,WAAE,CAACC,UAAU,CAAC1C,WAAW,CAAC,EAAE;MAC9B,IAAAkC,6BAAkB,EAAClC,WAAW,EAAE,EAAE,CAAC;IACrC;IAEApB,QAAQ,CAAC,IAAI,EAAEN,MAAM,CAACkE,IAAI,GAAApB,kBAAA,GAAE9C,MAAM,CAACU,SAAS,cAAAoC,kBAAA,cAAAA,kBAAA,GAAI5D,SAAS,CAAC;EAC5D,CAAC,CAAC,CACDmF,KAAK,CAAEtE,GAAU,IAAKO,QAAQ,CAACP,GAAG,CAAC,CAAC;AACzC,CAAC;AAAC,IAAAuE,QAAA,GAAAC,OAAA,CAAAzG,OAAA,GAEamC,eAAe","ignoreList":[]}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.insertImportStatement = insertImportStatement;
7
+ /**
8
+ * Insert an import statement in a safe position:
9
+ * - after the last existing import declaration,
10
+ * - otherwise after the directive prologue (e.g. 'use client'),
11
+ * - otherwise at the top of the file.
12
+ */
13
+ function insertImportStatement(code, importStatement) {
14
+ if (code.includes(importStatement)) {
15
+ return code;
16
+ }
17
+ const importRegex = /^\s*(?:import\s+[^;]+?\s+from\s+["'][^"']+["'];|import\s*["'][^"']+["'];)/gm;
18
+ const importMatches = [...code.matchAll(importRegex)];
19
+ if (importMatches.length > 0) {
20
+ const lastImport = importMatches[importMatches.length - 1];
21
+ const insertPosition = lastImport.index + lastImport[0].length;
22
+ return `${code.slice(0, insertPosition)}\n${importStatement}${code.slice(insertPosition)}`;
23
+ }
24
+ const directiveRegex = /^(?:(?:\s*["']use \w+["'];?\s*\n?)+)/;
25
+ const directiveMatch = code.match(directiveRegex);
26
+ if (directiveMatch) {
27
+ const endOfDirectives = directiveMatch[0].length;
28
+ const needsNewline = !code.slice(0, endOfDirectives).endsWith('\n');
29
+ const separator = needsNewline ? '\n' : '';
30
+ return `${code.slice(0, endOfDirectives)}${separator}${importStatement}\n${code.slice(endOfDirectives)}`;
31
+ }
32
+ return `${importStatement}\n${code}`;
33
+ }
34
+ //# sourceMappingURL=insert-import.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insert-import.js","names":["insertImportStatement","code","importStatement","includes","importRegex","importMatches","matchAll","length","lastImport","insertPosition","index","slice","directiveRegex","directiveMatch","match","endOfDirectives","needsNewline","endsWith","separator"],"sources":["../src/insert-import.ts"],"sourcesContent":["/**\n * Insert an import statement in a safe position:\n * - after the last existing import declaration,\n * - otherwise after the directive prologue (e.g. 'use client'),\n * - otherwise at the top of the file.\n */\nexport function insertImportStatement(code: string, importStatement: string) {\n if (code.includes(importStatement)) {\n return code;\n }\n\n const importRegex =\n /^\\s*(?:import\\s+[^;]+?\\s+from\\s+[\"'][^\"']+[\"'];|import\\s*[\"'][^\"']+[\"'];)/gm;\n const importMatches = [...code.matchAll(importRegex)];\n if (importMatches.length > 0) {\n const lastImport = importMatches[importMatches.length - 1];\n const insertPosition = lastImport.index! + lastImport[0].length;\n return `${code.slice(0, insertPosition)}\\n${importStatement}${code.slice(\n insertPosition\n )}`;\n }\n\n const directiveRegex = /^(?:(?:\\s*[\"']use \\w+[\"'];?\\s*\\n?)+)/;\n const directiveMatch = code.match(directiveRegex);\n if (directiveMatch) {\n const endOfDirectives = directiveMatch[0].length;\n const needsNewline = !code.slice(0, endOfDirectives).endsWith('\\n');\n const separator = needsNewline ? '\\n' : '';\n return `${code.slice(\n 0,\n endOfDirectives\n )}${separator}${importStatement}\\n${code.slice(endOfDirectives)}`;\n }\n\n return `${importStatement}\\n${code}`;\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,qBAAqBA,CAACC,IAAY,EAAEC,eAAuB,EAAE;EAC3E,IAAID,IAAI,CAACE,QAAQ,CAACD,eAAe,CAAC,EAAE;IAClC,OAAOD,IAAI;EACb;EAEA,MAAMG,WAAW,GACf,6EAA6E;EAC/E,MAAMC,aAAa,GAAG,CAAC,GAAGJ,IAAI,CAACK,QAAQ,CAACF,WAAW,CAAC,CAAC;EACrD,IAAIC,aAAa,CAACE,MAAM,GAAG,CAAC,EAAE;IAC5B,MAAMC,UAAU,GAAGH,aAAa,CAACA,aAAa,CAACE,MAAM,GAAG,CAAC,CAAC;IAC1D,MAAME,cAAc,GAAGD,UAAU,CAACE,KAAK,GAAIF,UAAU,CAAC,CAAC,CAAC,CAACD,MAAM;IAC/D,OAAO,GAAGN,IAAI,CAACU,KAAK,CAAC,CAAC,EAAEF,cAAc,CAAC,KAAKP,eAAe,GAAGD,IAAI,CAACU,KAAK,CACtEF,cACF,CAAC,EAAE;EACL;EAEA,MAAMG,cAAc,GAAG,sCAAsC;EAC7D,MAAMC,cAAc,GAAGZ,IAAI,CAACa,KAAK,CAACF,cAAc,CAAC;EACjD,IAAIC,cAAc,EAAE;IAClB,MAAME,eAAe,GAAGF,cAAc,CAAC,CAAC,CAAC,CAACN,MAAM;IAChD,MAAMS,YAAY,GAAG,CAACf,IAAI,CAACU,KAAK,CAAC,CAAC,EAAEI,eAAe,CAAC,CAACE,QAAQ,CAAC,IAAI,CAAC;IACnE,MAAMC,SAAS,GAAGF,YAAY,GAAG,IAAI,GAAG,EAAE;IAC1C,OAAO,GAAGf,IAAI,CAACU,KAAK,CAClB,CAAC,EACDI,eACF,CAAC,GAAGG,SAAS,GAAGhB,eAAe,KAAKD,IAAI,CAACU,KAAK,CAACI,eAAe,CAAC,EAAE;EACnE;EAEA,OAAO,GAAGb,eAAe,KAAKD,IAAI,EAAE;AACtC","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@wyw-in-js/turbopack-loader",
3
+ "version": "1.0.0",
4
+ "dependencies": {
5
+ "@wyw-in-js/shared": "workspace:*",
6
+ "@wyw-in-js/transform": "workspace:*"
7
+ },
8
+ "devDependencies": {
9
+ "@types/node": "^16.18.55",
10
+ "@wyw-in-js/babel-config": "workspace:*",
11
+ "@wyw-in-js/eslint-config": "workspace:*",
12
+ "@wyw-in-js/ts-config": "workspace:*",
13
+ "source-map": "^0.7.4",
14
+ "webpack": "^5.76.0"
15
+ },
16
+ "engines": {
17
+ "node": ">=16.0.0"
18
+ },
19
+ "files": [
20
+ "esm/",
21
+ "lib/",
22
+ "types/"
23
+ ],
24
+ "license": "MIT",
25
+ "main": "lib/index.js",
26
+ "module": "esm/index.js",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
32
+ "build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
33
+ "build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
34
+ "lint": "eslint --ext .js,.ts .",
35
+ "test": "bun test src"
36
+ },
37
+ "types": "types/index.d.ts"
38
+ }
@@ -0,0 +1 @@
1
+ export declare function makeCssModuleGlobal(cssText: string): string;
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeCssModuleGlobal = makeCssModuleGlobal;
4
+ const nestingAtRules = new Set([
5
+ 'container',
6
+ 'document',
7
+ 'layer',
8
+ 'media',
9
+ 'scope',
10
+ 'starting-style',
11
+ 'supports',
12
+ ]);
13
+ function isWhitespace(char) {
14
+ return (char === ' ' ||
15
+ char === '\n' ||
16
+ char === '\r' ||
17
+ char === '\t' ||
18
+ char === '\f');
19
+ }
20
+ function isKeyframesAtRule(name) {
21
+ return name.toLowerCase().endsWith('keyframes');
22
+ }
23
+ function readString(css, start) {
24
+ const quote = css[start];
25
+ let idx = start + 1;
26
+ while (idx < css.length) {
27
+ const char = css[idx];
28
+ if (char === '\\') {
29
+ idx += 2;
30
+ }
31
+ else if (char === quote) {
32
+ return idx + 1;
33
+ }
34
+ else {
35
+ idx += 1;
36
+ }
37
+ }
38
+ return css.length;
39
+ }
40
+ function readComment(css, start) {
41
+ const end = css.indexOf('*/', start + 2);
42
+ return end === -1 ? css.length : end + 2;
43
+ }
44
+ function findAtRuleTerminator(css, start) {
45
+ let idx = start;
46
+ let parenDepth = 0;
47
+ let bracketDepth = 0;
48
+ while (idx < css.length) {
49
+ const char = css[idx];
50
+ if (char === '/' && css[idx + 1] === '*') {
51
+ idx = readComment(css, idx);
52
+ }
53
+ else if (char === '"' || char === "'") {
54
+ idx = readString(css, idx);
55
+ }
56
+ else {
57
+ if (char === '(')
58
+ parenDepth += 1;
59
+ else if (char === ')' && parenDepth > 0)
60
+ parenDepth -= 1;
61
+ else if (char === '[')
62
+ bracketDepth += 1;
63
+ else if (char === ']' && bracketDepth > 0)
64
+ bracketDepth -= 1;
65
+ if (parenDepth === 0 &&
66
+ bracketDepth === 0 &&
67
+ (char === ';' || char === '{')) {
68
+ return idx;
69
+ }
70
+ idx += 1;
71
+ }
72
+ }
73
+ return css.length;
74
+ }
75
+ function findMatchingBrace(css, openBraceIdx) {
76
+ let idx = openBraceIdx + 1;
77
+ let depth = 1;
78
+ while (idx < css.length) {
79
+ const char = css[idx];
80
+ if (char === '/' && css[idx + 1] === '*') {
81
+ idx = readComment(css, idx);
82
+ }
83
+ else if (char === '"' || char === "'") {
84
+ idx = readString(css, idx);
85
+ }
86
+ else {
87
+ if (char === '{')
88
+ depth += 1;
89
+ else if (char === '}') {
90
+ depth -= 1;
91
+ if (depth === 0)
92
+ return idx;
93
+ }
94
+ idx += 1;
95
+ }
96
+ }
97
+ return -1;
98
+ }
99
+ function splitSelectorList(selectorText) {
100
+ const parts = [];
101
+ let start = 0;
102
+ let idx = 0;
103
+ let parenDepth = 0;
104
+ let bracketDepth = 0;
105
+ while (idx < selectorText.length) {
106
+ const char = selectorText[idx];
107
+ if (char === '/' && selectorText[idx + 1] === '*') {
108
+ idx = readComment(selectorText, idx);
109
+ }
110
+ else if (char === '"' || char === "'") {
111
+ idx = readString(selectorText, idx);
112
+ }
113
+ else {
114
+ if (char === '(')
115
+ parenDepth += 1;
116
+ else if (char === ')' && parenDepth > 0)
117
+ parenDepth -= 1;
118
+ else if (char === '[')
119
+ bracketDepth += 1;
120
+ else if (char === ']' && bracketDepth > 0)
121
+ bracketDepth -= 1;
122
+ if (parenDepth === 0 && bracketDepth === 0 && char === ',') {
123
+ parts.push(selectorText.slice(start, idx));
124
+ start = idx + 1;
125
+ }
126
+ idx += 1;
127
+ }
128
+ }
129
+ parts.push(selectorText.slice(start));
130
+ return parts;
131
+ }
132
+ function wrapSelector(selectorText) {
133
+ const selectors = splitSelectorList(selectorText)
134
+ .map((s) => s.trim())
135
+ .filter(Boolean);
136
+ return selectors.map((selector) => `:global(${selector})`).join(', ');
137
+ }
138
+ function wrapKeyframesHeader(prelude) {
139
+ let idx = 0;
140
+ while (idx < prelude.length && isWhitespace(prelude[idx]))
141
+ idx += 1;
142
+ if (prelude.slice(idx).startsWith(':global(')) {
143
+ return prelude;
144
+ }
145
+ const match = /^[A-Za-z_-][A-Za-z0-9_-]*/.exec(prelude.slice(idx));
146
+ if (!match)
147
+ return prelude;
148
+ const name = match[0];
149
+ const before = prelude.slice(0, idx);
150
+ const after = prelude.slice(idx + name.length);
151
+ return `${before}:global(${name})${after}`;
152
+ }
153
+ function makeCssModuleGlobalInner(css) {
154
+ let idx = 0;
155
+ let out = '';
156
+ while (idx < css.length) {
157
+ const char = css[idx];
158
+ if (isWhitespace(char)) {
159
+ out += char;
160
+ idx += 1;
161
+ }
162
+ else if (char === '/' && css[idx + 1] === '*') {
163
+ const end = readComment(css, idx);
164
+ out += css.slice(idx, end);
165
+ idx = end;
166
+ }
167
+ else if (char === '"' || char === "'") {
168
+ const end = readString(css, idx);
169
+ out += css.slice(idx, end);
170
+ idx = end;
171
+ }
172
+ else if (char === '@') {
173
+ const nameStart = idx + 1;
174
+ let nameEnd = nameStart;
175
+ while (nameEnd < css.length && /[A-Za-z0-9_-]/.test(css[nameEnd])) {
176
+ nameEnd += 1;
177
+ }
178
+ const atRuleName = css.slice(nameStart, nameEnd);
179
+ const terminatorIdx = findAtRuleTerminator(css, nameEnd);
180
+ const terminator = css[terminatorIdx];
181
+ const prelude = css.slice(nameEnd, terminatorIdx);
182
+ if (terminator === ';') {
183
+ out += css.slice(idx, terminatorIdx + 1);
184
+ idx = terminatorIdx + 1;
185
+ }
186
+ else if (terminator !== '{') {
187
+ out += css.slice(idx);
188
+ break;
189
+ }
190
+ else {
191
+ const blockEndIdx = findMatchingBrace(css, terminatorIdx);
192
+ if (blockEndIdx === -1) {
193
+ out += css.slice(idx);
194
+ break;
195
+ }
196
+ const blockBody = css.slice(terminatorIdx + 1, blockEndIdx);
197
+ if (isKeyframesAtRule(atRuleName)) {
198
+ out += `@${atRuleName}${wrapKeyframesHeader(prelude)}{${blockBody}}`;
199
+ }
200
+ else if (nestingAtRules.has(atRuleName.toLowerCase())) {
201
+ out += `@${atRuleName}${prelude}{${makeCssModuleGlobalInner(blockBody)}}`;
202
+ }
203
+ else {
204
+ out += `@${atRuleName}${prelude}{${blockBody}}`;
205
+ }
206
+ idx = blockEndIdx + 1;
207
+ }
208
+ }
209
+ else {
210
+ // A selector rule: read until '{' at top-level.
211
+ const openIdx = css.indexOf('{', idx);
212
+ if (openIdx === -1) {
213
+ out += css.slice(idx);
214
+ break;
215
+ }
216
+ const selectorText = css.slice(idx, openIdx).trim();
217
+ const blockEndIdx = findMatchingBrace(css, openIdx);
218
+ if (blockEndIdx === -1) {
219
+ out += css.slice(idx);
220
+ break;
221
+ }
222
+ const blockBody = css.slice(openIdx + 1, blockEndIdx);
223
+ out += `${wrapSelector(selectorText)}{${blockBody}}`;
224
+ idx = blockEndIdx + 1;
225
+ }
226
+ }
227
+ return out;
228
+ }
229
+ function makeCssModuleGlobal(cssText) {
230
+ return makeCssModuleGlobalInner(cssText);
231
+ }
@@ -0,0 +1 @@
1
+ export declare function writeFileIfChanged(filePath: string, content: string): boolean;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.writeFileIfChanged = writeFileIfChanged;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ function writeFileIfChanged(filePath, content) {
10
+ let previous = null;
11
+ try {
12
+ previous = fs_1.default.readFileSync(filePath, 'utf8');
13
+ }
14
+ catch (err) {
15
+ if (err.code !== 'ENOENT') {
16
+ throw err;
17
+ }
18
+ }
19
+ if (previous === content) {
20
+ return false;
21
+ }
22
+ const dir = path_1.default.dirname(filePath);
23
+ const tmpPath = path_1.default.join(dir, `${path_1.default.basename(filePath)}.${process.pid}.${Date.now()}.tmp`);
24
+ try {
25
+ fs_1.default.writeFileSync(tmpPath, content);
26
+ fs_1.default.renameSync(tmpPath, filePath);
27
+ }
28
+ finally {
29
+ try {
30
+ fs_1.default.unlinkSync(tmpPath);
31
+ }
32
+ catch {
33
+ // ignore
34
+ }
35
+ }
36
+ return true;
37
+ }
@@ -0,0 +1,10 @@
1
+ import type { RawLoaderDefinitionFunction } from 'webpack';
2
+ import type { PluginOptions } from '@wyw-in-js/transform';
3
+ export type LoaderOptions = {
4
+ keepComments?: boolean;
5
+ prefixer?: boolean;
6
+ sourceMap?: boolean;
7
+ } & Partial<PluginOptions>;
8
+ type Loader = RawLoaderDefinitionFunction<LoaderOptions>;
9
+ declare const turbopackLoader: Loader;
10
+ export default turbopackLoader;