Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(esm): convert @redwoodjs/project-config to ESM #9870

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/project-config/build.js
jtoar marked this conversation as resolved.
Show resolved Hide resolved
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' },
})
22 changes: 0 additions & 22 deletions packages/project-config/build.mjs

This file was deleted.

7 changes: 5 additions & 2 deletions packages/project-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
"directory": "packages/project-config"
},
"license": "MIT",
"type": "module",
"exports": {
".": "./dist/index.js"
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"default": "./dist/index.cjs"
},
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "yarn node ./build.mjs && run build:types",
"build": "yarn node ./build.js && run build:types",
"build:pack": "yarn pack -o redwoodjs-project-config.tgz",
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"",
Expand Down
2 changes: 1 addition & 1 deletion packages/project-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import toml from '@iarna/toml'
import merge from 'deepmerge'
import { env as envInterpolation } from 'string-env-interpolation'

import { getConfigPath } from './configPath'
import { getConfigPath } from './configPath.js'

export enum TargetEnum {
NODE = 'node',
Expand Down
2 changes: 1 addition & 1 deletion packages/project-config/src/configPath.ts
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'

Expand Down
8 changes: 4 additions & 4 deletions packages/project-config/src/index.ts
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'
4 changes: 2 additions & 2 deletions packages/project-config/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import path from 'path'

import fg from 'fast-glob'

import { getConfig } from './config'
import { getConfigPath } from './configPath'
import { getConfig } from './config.js'
import { getConfigPath } from './configPath.js'

export interface NodeTargetPaths {
base: string
Expand Down
2 changes: 2 additions & 0 deletions packages/project-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "../../tsconfig.compilerOption.json",
"compilerOptions": {
"moduleResolution": "NodeNext",
"module": "NodeNext",
Comment on lines +4 to +5
Copy link
Contributor Author

@jtoar jtoar Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These or some variant of them seem necessary for properly type checking an ES module. It doesn't seem like they actually affect the emitted *.d.ts files. Still figuring that out.

There's a bundler option we could use as well for moduleResolution but I don't see the value in it yet

"baseUrl": ".",
"rootDir": "src",
"outDir": "dist",
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/bins/rw-vite-dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { createServer } from 'vite'
import yargsParser from 'yargs-parser'

import projectConfig from '@redwoodjs/project-config'
Copy link
Contributor Author

@jtoar jtoar Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an mjs file so it would import the ESM version of @redwoodjs/project-config. The ESM version has no default export. I could've re-written this as

import * as projectConfig from '@redwoodjs/project-config'

but didn't see the point when we don't do that anywhere else

import { getPaths } from '@redwoodjs/project-config'

const rwPaths = projectConfig.getPaths()
const rwPaths = getPaths()

const startDevServer = async () => {
const configFile = rwPaths.web.viteConfig
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/__tests__/viteNestedPages.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { transformWithEsbuild } from 'vite'
import { test, describe, beforeEach, afterAll, beforeAll, it, expect, vi } from 'vitest'

import * as babel from '@babel/core'
import projectConfig from '@redwoodjs/project-config'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { getPaths } from '@redwoodjs/project-config'

import {
Flags,
Expand Down Expand Up @@ -41,7 +41,6 @@ async function transform(srcPath: string) {
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const FIXTURE_PATH = path.join(__dirname, 'fixtures/nestedPages')
const { getPaths } = projectConfig

test('transform', async () => {
vi.spyOn(fs, 'readFileSync').mockImplementationOnce(() => {
Expand Down
Loading