Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion javascript-modules-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@rollup/plugin-typescript": "^12.1.2",
"@types/node": "^22.13.5",
"devalue": "^5.1.1",
"rollup": "^4.34.8",
"rollup": "^4.35.0",
"rollup-plugin-sbom": "^2.0.2"
}
}
2 changes: 1 addition & 1 deletion vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/node": "^22.13.5",
"pkgroll": "^2.11.0",
"publint": "^0.3.6",
"rollup": "^4.34.8",
"rollup": "^4.35.0",
"vite": "^6.1.1"
},
"peerDependencies": {
Expand Down
8 changes: 2 additions & 6 deletions vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ const external = Object.keys(sharedLibs);

/** Plugin to execute a callback when a build succeeds. */
function buildSuccessPlugin(callback: () => void | Promise<void>): Plugin {
let succeeded = true;
return {
name: "build-success-callback",
buildEnd(error) {
succeeded = !error;
},
async closeBundle() {
if (succeeded) await callback();
async closeBundle(error) {
if (!error) await callback();
},
};
}
Expand Down
16 changes: 8 additions & 8 deletions vite-plugin/src/insert-filename.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { print } from "esrap";
import type { Node } from "estree";
import { Plugin } from "rollup";
import type { Plugin } from "rollup";
import { walk } from "zimmerframe";
import { createFilter } from "@rollup/pluginutils";
import path from "path";
import path from "node:path";

/**
* This plugin adds a `__filename` property to all default exports.
Expand Down Expand Up @@ -44,7 +44,6 @@ export const insertFilename = (root: string, prefix: string): Plugin => {
const ast = walk(this.parse(code) as Node, null, {
// Only target `export default function`
ExportDefaultDeclaration(node) {
if (node.declaration.type !== "FunctionDeclaration") return;
return {
// export default
type: "ExportDefaultDeclaration",
Expand All @@ -64,11 +63,12 @@ export const insertFilename = (root: string, prefix: string): Plugin => {
property: { type: "Identifier", name: "defineProperty" },
},
arguments: [
{
// Original function
...node.declaration,
type: "FunctionExpression",
},
// Convert function and class declarations to expressions, keep others as is
node.declaration.type === "FunctionDeclaration"
? { ...node.declaration, type: "FunctionExpression" }
: node.declaration.type === "ClassDeclaration"
? { ...node.declaration, type: "ClassExpression" }
: node.declaration,
{ type: "Literal", value: "__filename" },
{
// { value: id, enumerable: false }
Expand Down
Loading