Skip to content

Commit

Permalink
revert bad formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Jan 17, 2024
1 parent 1116ec1 commit 68c5812
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions code/builders/builder-webpack5/src/loaders/export-order-loader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from "node:assert";
import { parse as parseCjs, init as initCjsParser } from "cjs-module-lexer";
import { parse as parseEs } from "es-module-lexer";
import MagicString from "magic-string";
import type { LoaderContext } from "webpack";
import assert from 'node:assert';
import { parse as parseCjs, init as initCjsParser } from 'cjs-module-lexer';
import { parse as parseEs } from 'es-module-lexer';
import MagicString from 'magic-string';
import type { LoaderContext } from 'webpack';

export default async function loader(
this: LoaderContext<any>,
Expand All @@ -22,34 +22,30 @@ export default async function loader(
const parseResult = await parseEs(source);
const namedExportsOrder = (parseResult[1] || [])
.map((e) => source.substring(e.s, e.e))
.filter((e) => e !== "default");
.filter((e) => e !== 'default');

assert(
namedExportsOrder.length > 0,
"No named exports found. Very likely that this is not a ES module."
'No named exports found. Very likely that this is not a ES module.'
);

magicString.append(
`;export const __namedExportsOrder = ${JSON.stringify(
namedExportsOrder
)};`
`;export const __namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
);
// Try to parse as CJS module
} catch {
await initCjsParser();
const namedExportsOrder = (parseCjs(source).exports || []).filter(
(e: string) => e !== "default" && e !== "__esModule"
(e: string) => e !== 'default' && e !== '__esModule'
);

assert(
namedExportsOrder.length > 0,
"No named exports found. Very likely that this is not a CJS module."
'No named exports found. Very likely that this is not a CJS module.'
);

magicString.append(
`;module.exports.__namedExportsOrder = ${JSON.stringify(
namedExportsOrder
)};`
`;module.exports.__namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
);
}

Expand Down

0 comments on commit 68c5812

Please sign in to comment.