Skip to content

Commit

Permalink
fix sourcemap reference error (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim authored Jun 14, 2024
1 parent f054f01 commit 04fe2fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .changeset/big-laws-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"unicode-segmenter": patch
---

Fix sourcemap reference error

- Include missing sourcemap files for transformed cjs entries
- Remove unnecessary transforms for esm entries and remove source map reference
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"files": [
"/*.js",
"/*.cjs",
"/*.cjs.map",
"/*.d.ts",
"/src",
"/licenses"
Expand Down
28 changes: 14 additions & 14 deletions scripts/build-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let bundleDir = path.join(distDir, 'bundle');
await fs.mkdir(distDir, { recursive: true });

let src = name => path.join(srcDir, name);
let dist = name => path.join(distDir, name);
let modules = await fs.readdir(srcDir);

function rewriteCjs(content) {
Expand All @@ -20,28 +21,27 @@ function rewriteCjs(content) {
}

{
let entryPoints = modules.map(src);
await build({
entryPoints,
outdir: distDir,
outExtension: { '.js': '.js' },
format: 'esm',
treeShaking: true,
write: true,
sourcemap: true,
});
// use source modules as is
await Promise.all(
modules.map(
module => fs.copyFile(src(module), dist(module)),
),
);

let { outputFiles: cjsOutputs } = await build({
entryPoints,
entryPoints: modules.map(src),
outdir: distDir,
outExtension: { '.js': '.cjs' },
format: 'cjs',
treeShaking: true,
write: false,
sourcemap: true,
});
for (let { path, text } of cjsOutputs) {
await fs.writeFile(path, rewriteCjs(text), 'utf8');
}
await Promise.all(
cjsOutputs.map(
({ path, text }) => fs.writeFile(path, rewriteCjs(text), 'utf8'),
),
);
}

{
Expand Down

0 comments on commit 04fe2fc

Please sign in to comment.