forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(esm): convert
@redwoodjs/project-config
to ESM (redwoodjs#9870)
I'm still working through a few things. The motivation for tackling `@redwoodjs/project-config` first was 1) most of our other package's depend on it 2) it's small 3) it would make merging the PR that converts the CLI's Jest tests to Vitest easier because Vitest can't mock require (see redwoodjs#9863). I used [`arethetypeswrong/cli`](https://github.com/arethetypeswrong/arethetypeswrong.github.io) extensively. Right now I'm deeming the "Masquerading as ESM" error it emits acceptable. The code between the ESM and CJS files doesn't differ in functionality, only syntax; shipping two declaration copies of all the declaration files is shipping extra code. Mark Erikson did something similar at first at least here: > Unfortunately, no build tool that I knew of at that time did this by default, and the idea of shipping 99%-duplicate typedefs bothered me. So, I opted to not try to fix this "FalseCJS" issue for our packages (at least for the time being). (Source: https://blog.isquaredsoftware.com/2023/08/esm-modernization-lessons/#typescript-declarations.) Note that FalseCJS's fancier name is "Masquerading as CJS". We have "Masquerading as ESM", not CJS. I'm not sure if it's an issue that it's flipped yet. ``` $ attw ./redwoodjs-project-config.tgz @redwoodjs/project-config v6.0.7 Build tools: - typescript@5.3.3 - esbuild@0.19.9 👺 Import resolved to an ESM type declaration file, but a CommonJS JavaScript file. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md ┌───────────────────┬─────────────────────────────┐ │ │ "@redwoodjs/project-config" │ ├───────────────────┼─────────────────────────────┤ │ node10 │ 🟢 │ ├───────────────────┼─────────────────────────────┤ │ node16 (from CJS) │ 👺 Masquerading as ESM │ ├───────────────────┼─────────────────────────────┤ │ node16 (from ESM) │ 🟢 (ESM) │ ├───────────────────┼─────────────────────────────┤ │ bundler │ 🟢 │ └───────────────────┴─────────────────────────────┘ ``` Regarding the `.js` extensions (which are necessary for relative imports in ESM) in TS code, see redwoodjs#8456.
- Loading branch information
Showing
10 changed files
with
46 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
|
||
import * as esbuild from 'esbuild' | ||
|
||
const options = { | ||
entryPoints: ['./src/index.ts'], | ||
outdir: 'dist', | ||
|
||
platform: 'node', | ||
target: ['node20'], | ||
bundle: true, | ||
packages: 'external', | ||
|
||
logLevel: 'info', | ||
metafile: true, | ||
} | ||
|
||
await esbuild.build({ | ||
...options, | ||
format: 'esm', | ||
outExtension: { '.js': '.mjs' }, | ||
}) | ||
|
||
await esbuild.build({ | ||
...options, | ||
format: 'cjs', | ||
outExtension: { '.js': '.cjs' }, | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { findUp } from './findUp' | ||
import { findUp } from './findUp.js' | ||
|
||
const CONFIG_FILE_NAME = 'redwood.toml' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './config' | ||
export * from './configPath' | ||
export * from './paths' | ||
export * from './findUp' | ||
export * from './config.js' | ||
export * from './configPath.js' | ||
export * from './paths.js' | ||
export * from './findUp.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters