@windicss/plugin-utils
Advanced tools
Comparing version 0.10.3 to 0.10.4
@@ -202,7 +202,7 @@ import { FullConfig } from 'windicss/types/interfaces'; | ||
/** | ||
* Use esbuild-register to load configs in TypeScript | ||
* Use sucrase/register to load configs in ESM/TypeScript | ||
* | ||
* @default true | ||
*/ | ||
enabledTypeScriptConfig?: boolean; | ||
enableSucrase?: boolean; | ||
} | ||
@@ -209,0 +209,0 @@ interface ResolvedOptions { |
@@ -277,2 +277,33 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty; | ||
// src/register.ts | ||
var _pirates = require('pirates'); | ||
var _sucrase = require('sucrase'); | ||
function addHook2(extension, options, hookOptions) { | ||
return _pirates.addHook.call(void 0, (code, filePath) => { | ||
const {code: transformedCode, sourceMap} = _sucrase.transform.call(void 0, code, __assign(__assign({}, options), { | ||
sourceMapOptions: {compiledFilename: filePath}, | ||
filePath | ||
})); | ||
const mapBase64 = Buffer.from(JSON.stringify(sourceMap)).toString("base64"); | ||
const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`; | ||
return `${transformedCode} | ||
${suffix}`; | ||
}, __assign(__assign({}, hookOptions), {exts: [extension]})); | ||
} | ||
function registerJS(hookOptions) { | ||
return addHook2(".js", {transforms: ["imports"]}, hookOptions); | ||
} | ||
function registerTS(hookOptions) { | ||
return addHook2(".ts", {transforms: ["imports", "typescript"]}, hookOptions); | ||
} | ||
function registerSucrase() { | ||
const reverts = [ | ||
registerJS(), | ||
registerTS() | ||
]; | ||
return () => reverts.forEach((fn) => fn()); | ||
} | ||
// src/resolveOptions.ts | ||
@@ -370,3 +401,3 @@ function isResolvedOptions(options) { | ||
name = "windicss-plugin-utils", | ||
enabledTypeScriptConfig = true | ||
enableSucrase = true | ||
} = utilsOptions; | ||
@@ -395,6 +426,8 @@ const { | ||
if (configFilePath) { | ||
let revert = () => { | ||
}; | ||
try { | ||
debug("loading from ", configFilePath); | ||
if (enabledTypeScriptConfig && configFilePath.endsWith(".ts")) | ||
require("sucrase/register/ts"); | ||
if (enableSucrase) | ||
revert = registerSucrase(); | ||
delete require.cache[require.resolve(configFilePath)]; | ||
@@ -410,2 +443,4 @@ resolved = require(configFilePath); | ||
resolved = {}; | ||
} finally { | ||
revert(); | ||
} | ||
@@ -412,0 +447,0 @@ } |
{ | ||
"name": "@windicss/plugin-utils", | ||
"description": "Common utils for building integrations of Windi CSS", | ||
"version": "0.10.3", | ||
"version": "0.10.4", | ||
"main": "dist/index.js", | ||
@@ -34,2 +34,3 @@ "module": "dist/index.mjs", | ||
"micromatch": "^4.0.2", | ||
"pirates": "^4.0.1", | ||
"sucrase": "^3.17.1", | ||
@@ -36,0 +37,0 @@ "windicss": "^2.5.7" |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
54706
1695
0
7
+ Addedpirates@^4.0.1