@cedx/esbuild-plugins
Advanced tools
Comparing version
import process from "node:process"; | ||
import { | ||
packageDirectory | ||
} from "pkg-dir"; | ||
// Creates a plug-in that dedupes the specified modules. | ||
export var dedupeModules = function(modules, options = {}) { | ||
return { | ||
name: "DedupeModules", | ||
setup: function(build) { | ||
var resolveDir; | ||
({resolveDir = null} = options); | ||
build.onStart(async function() { | ||
if (resolveDir == null) { | ||
resolveDir = (await packageDirectory()) || process.cwd(); | ||
import { packageDirectory } from "pkg-dir"; | ||
/** | ||
* Creates a plug-in that dedupes the specified modules. | ||
* @param modules The list of modules to dedupe. | ||
* @param options The plug-in options. | ||
* @returns The newly created plug-in. | ||
*/ | ||
export function dedupeModules(modules, options = {}) { | ||
return { | ||
name: "DedupeModules", | ||
setup: (build) => { | ||
let { resolveDir = null } = options; | ||
build.onStart(async () => { resolveDir ??= await packageDirectory() ?? process.cwd(); }); // eslint-disable-line require-atomic-updates | ||
const resolveOptions = { namespace: "file", filter: new RegExp(`^(${modules.join("|")})(/|$)`) }; | ||
build.onResolve(resolveOptions, async (args) => await build.resolve(args.path, { kind: args.kind, resolveDir: resolveDir })); | ||
} | ||
}); | ||
build.onResolve({ | ||
namespace: "file", | ||
filter: new RegExp(`^(${modules.join("|")})(/|$)`) | ||
}, async function(args) { | ||
return (await build.resolve(args.path, { | ||
kind: args.kind, | ||
resolveDir: resolveDir | ||
})); | ||
}); | ||
} | ||
}; | ||
}; | ||
}; | ||
} |
export * from "./dedupe_modules.js"; | ||
export * from "./minify_html_literals.js"; |
@@ -1,42 +0,26 @@ | ||
import { | ||
minifyHTMLLiterals | ||
} from "minify-html-literals"; | ||
import { | ||
readFile | ||
} from "node:fs/promises"; | ||
import { | ||
EOL | ||
} from "node:os"; | ||
import { | ||
extname | ||
} from "node:path"; | ||
// Creates a plug-in that minifies HTML markup inside template literal strings. | ||
export var minifyHtmlLiterals = function(options = {}) { | ||
return { | ||
name: "MinifyHtmlLiterals", | ||
setup: function(build) { | ||
var filter, minifyOptions, tsExtensions; | ||
({filter = /\.[jt]s$/i, ...minifyOptions} = options); | ||
tsExtensions = new Set([".cts", ".mts", ".ts"]); | ||
build.onLoad({ | ||
namespace: "file", | ||
filter: filter | ||
}, async function(args) { | ||
var code, contents, map, ref; | ||
contents = (await readFile(args.path, "utf8")); | ||
({code, map} = (ref = minifyHTMLLiterals(contents, minifyOptions)) != null ? ref : { | ||
code: contents, | ||
map: null | ||
}); | ||
return { | ||
loader: tsExtensions.has(extname(args.path).toLowerCase()) ? "ts" : "js", | ||
contents: map ? `${code}${EOL}//# sourceMappingURL=${map.toUrl()}` : code | ||
}; | ||
}); | ||
} | ||
}; | ||
}; | ||
import { minifyHTMLLiterals } from "minify-html-literals"; | ||
import { readFile } from "node:fs/promises"; | ||
import { EOL } from "node:os"; | ||
import { extname } from "node:path"; | ||
/** | ||
* Creates a plug-in that minifies HTML markup inside template literal strings. | ||
* @param options The plug-in options. | ||
* @returns The newly created plug-in. | ||
*/ | ||
export function minifyHtmlLiterals(options = {}) { | ||
return { | ||
name: "MinifyHtmlLiterals", | ||
setup: (build) => { | ||
const { filter = /\.[jt]s$/i, ...minifyOptions } = options; | ||
const tsExtensions = new Set([".cts", ".mts", ".ts"]); | ||
build.onLoad({ namespace: "file", filter }, async (args) => { | ||
const contents = await readFile(args.path, "utf8"); | ||
const { code, map } = minifyHTMLLiterals(contents, minifyOptions) ?? { code: contents, map: null }; | ||
return { | ||
loader: tsExtensions.has(extname(args.path).toLowerCase()) ? "ts" : "js", | ||
contents: map ? `${code}${EOL}//# sourceMappingURL=${map.toUrl()}` : code | ||
}; | ||
}); | ||
} | ||
}; | ||
} |
@@ -9,3 +9,3 @@ { | ||
"type": "module", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": { | ||
@@ -21,7 +21,9 @@ "email": "cedric@belin.io", | ||
"devDependencies": { | ||
"@coffeelint/cli": "^5.2.11", | ||
"@types/eslint__js": "^8.42.3", | ||
"@types/gulp": "^4.0.17", | ||
"@types/node": "^22.10.7", | ||
"@types/node": "^22.12.0", | ||
"esbuild": "^0.24.2", | ||
"gulp": "^5.0.0" | ||
"gulp": "^5.0.0", | ||
"typescript": "^5.7.3", | ||
"typescript-eslint": "^8.22.0" | ||
}, | ||
@@ -32,3 +34,3 @@ "engines": { | ||
"exports": { | ||
"types": "./src/index.d.ts", | ||
"types": "./lib/index.d.ts", | ||
"default": "./lib/index.js" | ||
@@ -35,0 +37,0 @@ }, |
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
8955
39.01%15
36.36%161
54.81%7
40%1
Infinity%