Skip to content

Commit

Permalink
drop cjs support, fix dynamic import in esm (#32)
Browse files Browse the repository at this point in the history
* add webpackIgnore: true comment to dynamic import

* drop cjs support
  • Loading branch information
dferber90 committed Oct 23, 2022
1 parent 9a48681 commit 888b861
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-tomatoes-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/edge-config': major
---

drop cjs support
5 changes: 5 additions & 0 deletions .changeset/olive-spiders-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/edge-config': patch
---

fix dynamic import by adding webpackIgnore comment
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"main": "./dist/index.cjs",
"exports": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ async function getLocalEdgeConfig(
edgeConfigId: string,
): Promise<EmbeddedEdgeConfig | null> {
const embeddedEdgeConfigPath = `/opt/edge-configs/${edgeConfigId}.json`;
return import(embeddedEdgeConfigPath).catch(
// the webpackIgnore: true comment below gets dropped by esbuild,
// but we add it back in manually using the onSuccess callback
return import(/* webpackIgnore: true */ embeddedEdgeConfigPath).catch(
() => null,
) as Promise<EmbeddedEdgeConfig | null>;
}
Expand Down
11 changes: 10 additions & 1 deletion tsup.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import fs from 'node:fs';
import { defineConfig } from 'tsup';

// eslint-disable-next-line import/no-default-export
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
format: ['esm'],
splitting: true,
sourcemap: false,
minify: true,
clean: true,
skipNodeModulesBundle: true,
dts: true,
external: ['node_modules'],
onSuccess: () => {
const path = './dist/index.js';
const content = fs.readFileSync(path, 'utf-8');
fs.writeFileSync(
path,
content.replace('import(', 'import(/* webpackIgnore: true */'),
);
},
});

0 comments on commit 888b861

Please sign in to comment.