Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: es-module-lexer ^1.0.0 #217

Merged
merged 4 commits into from
Apr 2, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/poor-crews-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vocab/webpack': patch
---

Update `es-module-lexer` dependency
2 changes: 1 addition & 1 deletion packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@vocab/core": "^1.6.2",
"cjs-module-lexer": "^1.2.2",
"debug": "^4.3.1",
"es-module-lexer": "^0.10.0",
"es-module-lexer": "^1.0.0",
"picocolors": "^1.0.0",
"virtual-resource-loader": "^1.0.1"
},
Expand Down
9 changes: 7 additions & 2 deletions packages/webpack/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ function renderLanguageLoaderAsync(
};
}

function findExportNames(source: string, mode: 'cjs'): string[];
function findExportNames(
source: string,
mode: 'esm',
): esModuleLexer.ExportSpecifier[];
function findExportNames(source: string, mode: 'cjs' | 'esm') {
if (mode === 'esm') {
const [, exports] = esModuleLexer.parse(source);
Expand Down Expand Up @@ -126,12 +131,12 @@ export default async function vocabLoader(this: LoaderContext, source: string) {
const esmExports = findExportNames(source, 'esm');
if (esmExports.length > 0) {
const exportName = esmExports[0];
trace(`Found ESM export '${exportName}' in ${this.resourcePath}`);
trace(`Found ESM export '${exportName.n}' in ${this.resourcePath}`);

result = /* ts */ `
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
${translations}
export { translations as ${exportName} };
export { translations as ${exportName.n} };
`;
} else {
// init needs to be called and waited upon
Expand Down
8 changes: 2 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.