Skip to content

Commit

Permalink
Latest bunchee
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Aug 16, 2024
1 parent 6b5b41c commit ad0bdf1
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 109 deletions.
2 changes: 1 addition & 1 deletion packages/next-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"@types/node": "^20.14.5",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"bunchee": "^5.2.2",
"bunchee": "^5.3.2",
"eslint": "^8.56.0",
"eslint-config-molindo": "^7.0.0",
"eslint-plugin-deprecation": "^3.0.0",
Expand Down
48 changes: 1 addition & 47 deletions packages/next-intl/scripts/patch-dist.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* eslint-env node */
/* eslint-disable import/no-extraneous-dependencies */
import fs, {readFileSync} from 'fs';
import path from 'path';
import {globSync} from 'glob';
import fs from 'fs';

function patchFile(filePath, oldString, newString) {
const data = fs.readFileSync(filePath, 'utf8');
Expand All @@ -24,46 +21,3 @@ patchFile(
'export { createNextIntlPlugin as default };',
'export = createNextIntlPlugin;'
);

/**
* Patch declaration file for shared react-server runtime
*
* Workaround for: https://github.com/huozhi/bunchee/issues/547
*/
{
const result = /\/react-server-shared-[^.]+\.js/.exec(
readFileSync('./dist/esm/server.d.mts', 'utf8')
);
if (!result) {
throw new Error('Could not find the shared react-server runtime import');
}
const filename = result[0].substring(1);
const newFilename = filename.replace(/\.js$/, '.d.mts');
patchFile('./dist/esm/server.d.mts', filename, newFilename);

fs.renameSync(
path.resolve(process.cwd(), './dist/esm', filename),
`./dist/esm/${newFilename}`
);
}

/**
* Patch file extensions of separated chunks in the ESM build
*
* Workaround for: https://github.com/huozhi/bunchee/issues/557
*/
globSync('./dist/esm/**/*.js').forEach((filePath) => {
const filename = filePath.split('/').pop();
const newFilename = filename.replace(/\.js$/, '.mjs');

// rename the file extension
const newFilePath = filePath.replace(filename, newFilename);
fs.renameSync(filePath, newFilePath);

// patch all files in the esm folder that contain a reference to the original .js file
globSync('./dist/esm/**/*.mjs').forEach((importingFilePath) => {
patchFile(importingFilePath, filename, newFilename);
});
});

console.log('\n✔ Patched files in ./dist');
2 changes: 1 addition & 1 deletion packages/use-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"@types/node": "^20.14.5",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"bunchee": "^5.2.2",
"bunchee": "^5.3.2",
"date-fns": "^3.6.0",
"eslint": "^8.56.0",
"eslint-config-molindo": "^7.0.0",
Expand Down
Loading

0 comments on commit ad0bdf1

Please sign in to comment.