-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fixes #7951: prevent remix.init errors when init script is an ES6 module, update docs to clarify init script requirements #8100
Changes from 9 commits
053cb6d
e87649c
58e90a9
2ee1919
052c076
9c1adca
c278a83
747e1d7
c9bcc87
12e1434
70de3bb
bf8d7bc
261d3ae
76e0a68
ed1078e
9b7c69e
3f80c6d
c52e2c5
593a5dd
14b7aaf
7b9c2f3
7c61603
f099134
f67ea02
e8d00c7
92bdc30
1a3d619
03646eb
ad5c5b6
e84281e
f5baf4c
8ae9579
1ed86b3
aabbcaa
b6accdd
c64d0d9
af56384
102490d
29809a9
e3d0608
f90b64d
f20d7dd
8225de4
21cbb77
d15e2a8
0519f57
b2dec9c
2100928
766e07b
794afa9
299d203
66d945d
cbf288a
9d28ab6
035becf
8e52f34
cdfb761
a2aac31
cea3080
8e448b6
73a92dd
e42c732
22cb64b
7b750d1
41bd56a
1b7dd69
4006f9b
cde35e4
3b788bc
4bf8653
86bcfbd
2a57eae
7e1b974
6e8c447
41d0187
873ec19
d5ade44
0cd4281
8872316
d37073d
27cb926
87534a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,6 +323,7 @@ | |
- lensbart | ||
- leo | ||
- leon | ||
- leothorp | ||
- leovander | ||
- levippaul | ||
- LewisArdern | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "remix-init-as-es6-module-test", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"remix-init": "remix init" | ||
}, | ||
"devDependencies": { | ||
"@remix-run/dev": "latest" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
export default ({rootDirectory}) => { | ||
fs.writeFileSync( | ||
path.join(rootDirectory, "es6-remix-init-test.txt"), | ||
"added via es6 remix.init" | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "no-export-remix-init-test", | ||
"private": true, | ||
"main": "remix.int/index.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const fs = require("node:fs"); | ||
|
||
fs.writeFileSync( | ||
"./no-export-remix-init.txt", | ||
"added via remix.init with no export" | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,12 +44,15 @@ export async function init( | |
}); | ||
} | ||
|
||
let initFn = require(initScript); | ||
let initFn = await import(initScript); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Covered by the "succeeds for remix.init defined as an ES6 module" test. |
||
|
||
if (typeof initFn !== "function" && initFn.default) { | ||
initFn = initFn.default; | ||
} | ||
try { | ||
await initFn({ packageManager, rootDirectory: projectDir }); | ||
if (typeof initFn === "function") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Covered by the "succeeds for a remix.init script that doesn't default export a function" test. |
||
await initFn({ packageManager, rootDirectory: projectDir }); | ||
} | ||
|
||
if (deleteScript) { | ||
await fse.remove(initScriptDir); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stuff with copying over the newly-built version of @remix-run/dev and running it as a node module in the temp project is clunky, but was the only way I could reproduce the failing behavior of an es6 module init script throwing an error in the unit tests. With run(["init"]) the test always succeeds with the old code, even though
remix init
errors in actual use.It seems like some aspect of the
run(["init"])
calls used by other tests here doesn't fully replicate the real-world behavior of runningremix init
as a project dependency, so this was the only workaround I found initially .