-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable nested optimization (#157)
* wip: enable nested optimization - reorganized test dependencies and added cjs/esm deps * fix: process cjs-only on vite build * chore: add optimization test * chore: update vite peer dep * chore: improve code formatting in _test_dependencies Co-authored-by: Ben McCann <[email protected]> * fix: update vite to 2.5.3 to consume fix for windows problem Co-authored-by: bluwy <[email protected]> Co-authored-by: Ben McCann <[email protected]>
- Loading branch information
1 parent
908b838
commit 61a37a5
Showing
48 changed files
with
252 additions
and
129 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,7 @@ | ||
--- | ||
'@sveltejs/vite-plugin-svelte': major | ||
--- | ||
|
||
Enable optimization for nested dependencies of excluded svelte dependencies | ||
|
||
Vite 2.5.3 and above is needed to support this feature. |
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 @@ | ||
This directory contains packages that are used as dependencies in various e2e tests |
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,3 @@ | ||
module.exports = { | ||
cjs_and_esm: () => 'cjs' | ||
} |
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 @@ | ||
export function cjs_and_esm() { return 'esm' }; |
19 changes: 19 additions & 0 deletions
19
packages/e2e-tests/_test_dependencies/cjs-and-esm/package.json
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,19 @@ | ||
{ | ||
"version": "1.0.0", | ||
"private": true, | ||
"name": "e2e-test-dep-cjs-and-esm", | ||
"main": "index.cjs", | ||
"module": "index.mjs", | ||
"files": [ | ||
"package.json", | ||
"index.mjs", | ||
"index.cjs" | ||
], | ||
"exports":{ | ||
".": { | ||
"import": "./index.mjs", | ||
"require": "./index.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
} | ||
} |
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,3 @@ | ||
module.exports = { | ||
cjs: () => 'cjs' | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/e2e-tests/_test_dependencies/cjs-only/package.json
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,11 @@ | ||
{ | ||
"version": "1.0.0", | ||
"private": true, | ||
"name": "e2e-test-dep-cjs-only", | ||
"main": "index.js", | ||
"files": [ | ||
"package.json", | ||
"index.js" | ||
], | ||
"type": "commonjs" | ||
} |
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,3 @@ | ||
export function esm() { | ||
return 'esm'; | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/e2e-tests/_test_dependencies/esm-only/package.json
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,18 @@ | ||
{ | ||
"version": "1.0.0", | ||
"private": true, | ||
"name": "e2e-test-dep-esm-only", | ||
"main": "index.js", | ||
"module": "index.js", | ||
"files": [ | ||
"package.json", | ||
"index.cjs" | ||
], | ||
"exports":{ | ||
".": { | ||
"import": "./index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"type": "module" | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/e2e-tests/_test_dependencies/svelte-nested/package.json
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,18 @@ | ||
{ | ||
"version": "1.0.0", | ||
"private": true, | ||
"name": "e2e-test-dep-svelte-nested", | ||
"svelte": "src/index.js", | ||
"main": "src/index.js", | ||
"files": [ | ||
"src", | ||
"package.json" | ||
], | ||
"exports": { | ||
"./package.json": "./package.json" | ||
}, | ||
"dependencies": { | ||
"e2e-test-dep-svelte-simple": "workspace:*", | ||
"e2e-test-dep-cjs-and-esm": "workspace:*" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/e2e-tests/_test_dependencies/svelte-nested/src/components/Message.svelte
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,8 @@ | ||
<script> | ||
export let id = 'id'; | ||
export let message = ''; | ||
import { cjs_and_esm } from 'e2e-test-dep-cjs-and-esm'; | ||
</script> | ||
|
||
<div {id}>{message}</div> | ||
<div id="cjs-and-esm">{cjs_and_esm()}</div> |
2 changes: 2 additions & 0 deletions
2
packages/e2e-tests/_test_dependencies/svelte-nested/src/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Message from './components/Message.svelte'; | ||
export { Message }; |
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
packages/e2e-tests/_test_dependencies/svelte-simple/package.json
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,10 @@ | ||
{ | ||
"version": "1.0.0", | ||
"private": true, | ||
"name": "e2e-test-dep-svelte-simple", | ||
"main": "index.js", | ||
"svelte": "index.js", | ||
"dependencies": { | ||
"e2e-test-dep-cjs-only": "workspace:*" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...pendency/src/components/Dependency.svelte → ...e-simple/src/components/Dependency.svelte
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
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
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 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
19 changes: 18 additions & 1 deletion
19
packages/e2e-tests/package-json-svelte-field/__tests__/package-json-svelte-field.spec.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 |
---|---|---|
@@ -1,5 +1,22 @@ | ||
import { getText } from '../../testUtils'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { getText, isBuild } from '../../testUtils'; | ||
|
||
test('should render component imported via svelte field in package.json', async () => { | ||
expect(await getText('#test-id')).toBe('svelte field works'); | ||
}); | ||
|
||
if (!isBuild) { | ||
test('should optimize nested deps of excluded svelte deps', () => { | ||
const vitePrebundleMetadata = path.resolve(__dirname, '../node_modules/.vite/_metadata.json'); | ||
const metadataFile = fs.readFileSync(vitePrebundleMetadata, 'utf8'); | ||
const metadata = JSON.parse(metadataFile); | ||
const optimizedPaths = Object.keys(metadata.optimized); | ||
expect(optimizedPaths).not.toContain('e2e-test-dep-svelte-nested'); | ||
expect(optimizedPaths).not.toContain('e2e-test-dep-svelte-simple'); | ||
expect(optimizedPaths).toContain('e2e-test-dep-svelte-nested > e2e-test-dep-cjs-and-esm'); | ||
expect(optimizedPaths).toContain( | ||
'e2e-test-dep-svelte-nested > e2e-test-dep-svelte-simple > e2e-test-dep-cjs-only' | ||
); | ||
}); | ||
} |
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,6 +1,5 @@ | ||
<script> | ||
// eslint-disable-next-line node/no-missing-import | ||
import { Message } from 'e2e-tests-test-dependency-svelte-field'; | ||
import { Message } from 'e2e-test-dep-svelte-nested'; | ||
</script> | ||
|
||
<Message id="test-id" message="svelte field works" /> |
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
16 changes: 0 additions & 16 deletions
16
packages/e2e-tests/test-dependency-svelte-field/package.json
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
packages/e2e-tests/test-dependency-svelte-field/src/components/Message.svelte
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
packages/e2e-tests/test-dependency-svelte-field/src/components/svelte.js
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
Oops, something went wrong.