Skip to content

Commit

Permalink
fix: remove createRequire for package json (#978)
Browse files Browse the repository at this point in the history
follow up to this:
#974 (comment)

---------

Co-authored-by: Tyler <tyler@secondspectrum.com>
Co-authored-by: daishi <daishi@axlight.com>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent 0685bcf commit ef95f93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/create-waku/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, readdirSync } from 'node:fs';
import { existsSync, readdirSync, readFileSync } from 'node:fs';
import fsPromises from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
Expand All @@ -7,7 +7,6 @@ import { default as prompts } from 'prompts';
import { red, green, bold } from 'kolorist';
import fse from 'fs-extra/esm';
import checkForUpdate from 'update-check';
import { createRequire } from 'node:module';
import {
getTemplateNames,
installTemplate,
Expand Down Expand Up @@ -162,9 +161,7 @@ Options:
}

async function notifyUpdate() {
// keep original require to avoid
// bundling the whole package.json by `@vercel/ncc`
const packageJson = createRequire(import.meta.url)('../package.json');
const packageJson = JSON.parse(readFileSync('../package.json', 'utf8'));
const result = await checkForUpdate(packageJson).catch(() => {});
if (result?.latest) {
console.log(`A new version of 'create-waku' is available!`);
Expand Down
2 changes: 2 additions & 0 deletions packages/create-waku/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { defineConfig } from 'tsup';

export default defineConfig((options) => ({
entry: ['src/index.ts'],
external: [/package\.json/],
format: ['esm'],
minify: !options.watch,
clean: true,
/** @see https://github.com/egoist/tsup/issues/927#issuecomment-2354939322 */
banner: {
js: `import { createRequire } from 'module'; const require = createRequire(import.meta.url);`,
Expand Down

0 comments on commit ef95f93

Please sign in to comment.