-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove references to fs/promises and add a snapshot for esbuild to ma…
…intain compatibility
- Loading branch information
Luke Sheard
committed
Sep 21, 2021
1 parent
f6377a7
commit a99dea2
Showing
17 changed files
with
171 additions
and
16 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,6 @@ | ||
--- | ||
'modular-scripts': patch | ||
--- | ||
|
||
Remove references to fs/promises and add a snapshot for esbuild to maintain | ||
compatibility |
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
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
27 changes: 27 additions & 0 deletions
27
packages/modular-scripts/src/__tests__/__snapshots__/app.esbuild.test.ts.snap
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,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`when working with an app can generate a index.html 1`] = ` | ||
"<!DOCTYPE html> | ||
<html lang=\\"en\\"> | ||
<head> | ||
<meta charset=\\"utf-8\\" /> | ||
<link rel=\\"icon\\" href=\\"/favicon.ico\\" /> | ||
<meta name=\\"viewport\\" content=\\"width=device-width,initial-scale=1\\" /> | ||
<meta name=\\"theme-color\\" content=\\"#000000\\" /> | ||
<meta | ||
name=\\"description\\" | ||
content=\\"Web site created using create-modular-app\\" | ||
/> | ||
<link rel=\\"apple-touch-icon\\" href=\\"/logo192.png\\" /> | ||
<link rel=\\"manifest\\" href=\\"/manifest.json\\" /> | ||
<title>React App</title> | ||
<link rel=\\"stylesheet\\" href=\\"/index.css\\" /> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id=\\"root\\"></div> | ||
<script type=\\"module\\" src=\\"/index.js\\"></script> | ||
</body> | ||
</html> | ||
" | ||
`; |
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
110 changes: 110 additions & 0 deletions
110
packages/modular-scripts/src/__tests__/app.esbuild.test.ts
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,110 @@ | ||
import execa from 'execa'; | ||
import rimraf from 'rimraf'; | ||
import tree from 'tree-view-for-tests'; | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import prettier from 'prettier'; | ||
|
||
import getModularRoot from '../utils/getModularRoot'; | ||
|
||
const modularRoot = getModularRoot(); | ||
|
||
// These tests must be executed sequentially with `--runInBand`. | ||
|
||
const packagesPath = path.join(getModularRoot(), 'packages'); | ||
|
||
function modular(str: string, opts: Record<string, unknown> = {}) { | ||
return execa('yarnpkg', ['modular', ...str.split(' ')], { | ||
cwd: modularRoot, | ||
cleanup: true, | ||
// @ts-ignore | ||
env: { | ||
USE_MODULAR_ESBUILD: 'true', | ||
}, | ||
...opts, | ||
}); | ||
} | ||
|
||
function cleanup() { | ||
rimraf.sync(path.join(packagesPath, 'sample-esbuild-app')); | ||
rimraf.sync(path.join(modularRoot, 'dist/sample-esbuild-app')); | ||
|
||
// run yarn so yarn.lock gets reset | ||
return execa.sync('yarnpkg', ['--silent'], { | ||
cwd: modularRoot, | ||
}); | ||
} | ||
|
||
beforeAll(cleanup); | ||
afterAll(cleanup); | ||
|
||
describe('when working with an app', () => { | ||
beforeAll(async () => { | ||
await modular( | ||
'add sample-esbuild-app --unstable-type app --unstable-name sample-esbuild-app', | ||
{ stdio: 'inherit' }, | ||
); | ||
|
||
await modular('build sample-esbuild-app', { | ||
stdio: 'inherit', | ||
}); | ||
}); | ||
|
||
it('can add an app', () => { | ||
expect(tree(path.join(packagesPath, 'sample-esbuild-app'))) | ||
.toMatchInlineSnapshot(` | ||
"sample-esbuild-app | ||
├─ package.json | ||
├─ public | ||
│ ├─ favicon.ico #6pu3rg | ||
│ ├─ index.html #1wohq3p | ||
│ ├─ logo192.png #1nez7vk | ||
│ ├─ logo512.png #1hwqvcc | ||
│ ├─ manifest.json #19gah8o | ||
│ └─ robots.txt #1sjb8b3 | ||
├─ src | ||
│ ├─ App.css #1o0zosm | ||
│ ├─ App.tsx #c80ven | ||
│ ├─ __tests__ | ||
│ │ └─ App.test.tsx #16urcos | ||
│ ├─ index.css #o7sk21 | ||
│ ├─ index.tsx #zdn6mw | ||
│ ├─ logo.svg #1okqmlj | ||
│ └─ react-app-env.d.ts #t4ygcy | ||
└─ tsconfig.json #6rw46b" | ||
`); | ||
}); | ||
|
||
it('can build an app', () => { | ||
expect(tree(path.join(modularRoot, 'dist', 'sample-esbuild-app'))) | ||
.toMatchInlineSnapshot(` | ||
"sample-esbuild-app | ||
├─ favicon.ico #6pu3rg | ||
├─ index.css #1g5dmd3 | ||
├─ index.css.map #u2fo3e | ||
├─ index.html #1pinlfh | ||
├─ index.js #1o0ba8n | ||
├─ index.js.map #ek9rs | ||
├─ logo-PGX3QVVN.svg #1okqmlj | ||
├─ logo192.png #1nez7vk | ||
├─ logo512.png #1hwqvcc | ||
├─ manifest.json #19gah8o | ||
└─ robots.txt #1sjb8b3" | ||
`); | ||
}); | ||
|
||
it('can generate a index.html', async () => { | ||
expect( | ||
prettier.format( | ||
String( | ||
await fs.readFile( | ||
path.join(modularRoot, 'dist', 'sample-esbuild-app', 'index.html'), | ||
), | ||
), | ||
{ | ||
filepath: 'index.html', | ||
}, | ||
), | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
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
2 changes: 1 addition & 1 deletion
2
packages/modular-scripts/src/esbuild-scripts/plugins/incrementalCompile.ts
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 * as fs from 'fs/promises'; | ||
import * as fs from 'fs-extra'; | ||
import esbuild from 'esbuild'; | ||
|
||
// @ts-ignore | ||
|
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
2 changes: 1 addition & 1 deletion
2
packages/modular-scripts/src/esbuild-scripts/utils/formatError.ts
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