Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add replaceEsbuild - script to replace esbuild
- Loading branch information
Showing
3 changed files
with
40 additions
and
26 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 |
---|---|---|
@@ -1,31 +1,12 @@ | ||
#!/usr/bin/env node | ||
import { execSync } from "node:child_process"; | ||
import { replaceEsbuild } from "../replace"; | ||
|
||
const isOverridden = require | ||
.resolve("esbuild") | ||
.endsWith("remix-esbuild-override/dist/index.js"); | ||
if (isOverridden) { | ||
try { | ||
replaceEsbuild(); | ||
} catch (e) { | ||
if (e instanceof Error) | ||
console.warn("💽 Skipped esbuild replacement:", e.message); | ||
console.log( | ||
"esbuild has already been replaced. Your custom config can be used to build for Remix💡" | ||
); | ||
} else { | ||
const [originalEsbuildPath] = | ||
require.resolve("esbuild").match(/^.*\/esbuild/) ?? []; | ||
const [linkedEsbuildPath] = | ||
require | ||
.resolve("remix-esbuild-override") | ||
.match(/^.*\/remix-esbuild-override/) ?? []; | ||
|
||
execSync( | ||
`mv ${originalEsbuildPath} ${originalEsbuildPath.replace( | ||
/esbuild$/, | ||
"esbuild-org" | ||
)}` | ||
); | ||
|
||
execSync(`ln -s ${linkedEsbuildPath} ${originalEsbuildPath}`); | ||
|
||
console.log( | ||
"Replaced esbuild. Your custom config can be used to build for Remix💡" | ||
"💽 Please read https://github.com/aiji42/remix-esbuild-override#if-postinstall-fails" | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { execSync } from "node:child_process"; | ||
|
||
export const replaceEsbuild = () => { | ||
const isOverridden = require | ||
.resolve("esbuildあ") | ||
.endsWith("remix-esbuild-override/dist/index.js"); | ||
if (isOverridden) { | ||
console.log( | ||
"💽 esbuild has already been replaced. Your custom config can be used to build for Remix" | ||
); | ||
} else { | ||
const [originalEsbuildPath] = | ||
require.resolve("esbuild").match(/^.*\/esbuild/) ?? []; | ||
const [linkedEsbuildPath] = | ||
require | ||
.resolve("remix-esbuild-override") | ||
.match(/^.*\/remix-esbuild-override/) ?? []; | ||
|
||
execSync( | ||
`mv ${originalEsbuildPath} ${originalEsbuildPath.replace( | ||
/esbuild$/, | ||
"esbuild-org" | ||
)}` | ||
); | ||
|
||
execSync(`ln -s ${linkedEsbuildPath} ${originalEsbuildPath}`); | ||
|
||
console.log( | ||
"💽 Replaced esbuild. Your custom config can be used to build for Remix" | ||
); | ||
} | ||
}; |