@sveltejs/vite-plugin-svelte 1.0.0-next.44 → 1.0.0-next.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +20 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/ui/inspector/Inspector.svelte +1 -1
- package/src/ui/inspector/plugin.ts +1 -1
- package/src/utils/__tests__/dependencies.spec.ts +7 -4
- package/src/utils/__tests__/sourcemap.spec.ts +1 -0
- package/src/utils/compile.ts +2 -1
- package/src/utils/options.ts +26 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.45",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"debug": "^4.3.4",
|
|
46
46
|
"deepmerge": "^4.2.2",
|
|
47
47
|
"kleur": "^4.1.4",
|
|
48
|
-
"magic-string": "^0.26.
|
|
48
|
+
"magic-string": "^0.26.2",
|
|
49
49
|
"svelte-hmr": "^0.14.11"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
@@ -62,11 +62,11 @@
|
|
|
62
62
|
"@types/debug": "^4.1.7",
|
|
63
63
|
"@types/diff-match-patch": "^1.0.32",
|
|
64
64
|
"diff-match-patch": "^1.0.5",
|
|
65
|
-
"esbuild": "^0.14.
|
|
66
|
-
"rollup": "^2.
|
|
65
|
+
"esbuild": "^0.14.39",
|
|
66
|
+
"rollup": "^2.74.1",
|
|
67
67
|
"svelte": "^3.48.0",
|
|
68
|
-
"tsup": "^5.12.
|
|
69
|
-
"vite": "^2.9.
|
|
68
|
+
"tsup": "^5.12.8",
|
|
69
|
+
"vite": "^2.9.9"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"dev": "pnpm build:ci --sourcemap --watch src",
|
|
@@ -43,7 +43,7 @@ export function svelteInspector(): Plugin {
|
|
|
43
43
|
disabled = true;
|
|
44
44
|
} else {
|
|
45
45
|
if (vps.api.options.kit && !inspectorOptions.appendTo) {
|
|
46
|
-
const out_dir = vps.api.options.kit.outDir || '.svelte-kit';
|
|
46
|
+
const out_dir = path.basename(vps.api.options.kit.outDir || '.svelte-kit');
|
|
47
47
|
inspectorOptions.appendTo = `${out_dir}/runtime/client/start.js`;
|
|
48
48
|
}
|
|
49
49
|
appendTo = inspectorOptions.appendTo;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
1
2
|
import { findRootSvelteDependencies, needsOptimization } from '../dependencies';
|
|
2
3
|
import * as path from 'path';
|
|
3
4
|
import { createRequire } from 'module';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
const __dir = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const e2eTestRoot = path.resolve(__dir, '../../../../../packages/e2e-tests');
|
|
4
8
|
|
|
5
9
|
describe('dependencies', () => {
|
|
6
10
|
describe('findRootSvelteDependencies', () => {
|
|
@@ -11,9 +15,7 @@ describe('dependencies', () => {
|
|
|
11
15
|
expect(deps[0].path).toEqual([]);
|
|
12
16
|
});
|
|
13
17
|
it('should find nested svelte dependencies in packages/e2e-test/package-json-svelte-field', () => {
|
|
14
|
-
const deps = findRootSvelteDependencies(
|
|
15
|
-
path.resolve('packages/e2e-tests/package-json-svelte-field')
|
|
16
|
-
);
|
|
18
|
+
const deps = findRootSvelteDependencies(path.join(e2eTestRoot, 'package-json-svelte-field'));
|
|
17
19
|
expect(deps).toHaveLength(3);
|
|
18
20
|
const hybrid = deps.find((dep) => dep.name === 'e2e-test-dep-svelte-hybrid');
|
|
19
21
|
expect(hybrid).toBeTruthy();
|
|
@@ -29,7 +31,8 @@ describe('dependencies', () => {
|
|
|
29
31
|
});
|
|
30
32
|
describe('needsOptimization', () => {
|
|
31
33
|
it('should optimize cjs deps only', () => {
|
|
32
|
-
const
|
|
34
|
+
const testDepsPath = path.join(e2eTestRoot, 'dependencies/package.json');
|
|
35
|
+
const localRequire = createRequire(testDepsPath);
|
|
33
36
|
expect(needsOptimization('e2e-test-dep-cjs-and-esm', localRequire)).toBe(false);
|
|
34
37
|
expect(needsOptimization('e2e-test-dep-cjs-only', localRequire)).toBe(true);
|
|
35
38
|
expect(needsOptimization('e2e-test-dep-esm-only', localRequire)).toBe(false);
|
package/src/utils/compile.ts
CHANGED
|
@@ -21,7 +21,8 @@ const _createCompileSvelte = (makeHot: Function) =>
|
|
|
21
21
|
const compileOptions: CompileOptions = {
|
|
22
22
|
...options.compilerOptions,
|
|
23
23
|
filename,
|
|
24
|
-
generate: ssr ? 'ssr' : 'dom'
|
|
24
|
+
generate: ssr ? 'ssr' : 'dom',
|
|
25
|
+
format: 'esm'
|
|
25
26
|
};
|
|
26
27
|
if (options.hot && options.emitCss) {
|
|
27
28
|
const hash = `s-${safeBase64Hash(normalizedFilename)}`;
|
package/src/utils/options.ts
CHANGED
|
@@ -61,10 +61,7 @@ export async function preResolveOptions(
|
|
|
61
61
|
};
|
|
62
62
|
const defaultOptions: Partial<Options> = {
|
|
63
63
|
extensions: ['.svelte'],
|
|
64
|
-
emitCss: true
|
|
65
|
-
compilerOptions: {
|
|
66
|
-
format: 'esm'
|
|
67
|
-
}
|
|
64
|
+
emitCss: true
|
|
68
65
|
};
|
|
69
66
|
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions);
|
|
70
67
|
const extraOptions: Partial<PreResolvedOptions> = {
|
|
@@ -118,6 +115,7 @@ export function resolveOptions(
|
|
|
118
115
|
};
|
|
119
116
|
const merged: ResolvedOptions = mergeConfigs(defaultOptions, preResolveOptions, extraOptions);
|
|
120
117
|
|
|
118
|
+
removeIgnoredOptions(merged);
|
|
121
119
|
addExtraPreprocessors(merged, viteConfig);
|
|
122
120
|
enforceOptionsForHmr(merged);
|
|
123
121
|
enforceOptionsForProduction(merged);
|
|
@@ -177,6 +175,26 @@ function enforceOptionsForProduction(options: ResolvedOptions) {
|
|
|
177
175
|
}
|
|
178
176
|
}
|
|
179
177
|
|
|
178
|
+
function removeIgnoredOptions(options: ResolvedOptions) {
|
|
179
|
+
const ignoredCompilerOptions = ['generate', 'format', 'filename'];
|
|
180
|
+
if (options.hot && options.emitCss) {
|
|
181
|
+
ignoredCompilerOptions.push('cssHash');
|
|
182
|
+
}
|
|
183
|
+
const passedCompilerOptions = Object.keys(options.compilerOptions || {});
|
|
184
|
+
const passedIgnored = passedCompilerOptions.filter((o) => ignoredCompilerOptions.includes(o));
|
|
185
|
+
if (passedIgnored.length) {
|
|
186
|
+
log.warn(
|
|
187
|
+
`The following Svelte compilerOptions are controlled by vite-plugin-svelte and essential to its functionality. User-specified values are ignored. Please remove them from your configuration: ${passedIgnored.join(
|
|
188
|
+
', '
|
|
189
|
+
)}`
|
|
190
|
+
);
|
|
191
|
+
passedIgnored.forEach((ignored) => {
|
|
192
|
+
// @ts-expect-error string access
|
|
193
|
+
delete options.compilerOptions[ignored];
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
180
198
|
// vite passes unresolved `root`option to config hook but we need the resolved value, so do it here
|
|
181
199
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/113
|
|
182
200
|
// https://github.com/vitejs/vite/blob/43c957de8a99bb326afd732c962f42127b0a4d1e/packages/vite/src/node/config.ts#L293
|
|
@@ -401,11 +419,13 @@ export interface Options {
|
|
|
401
419
|
emitCss?: boolean;
|
|
402
420
|
|
|
403
421
|
/**
|
|
404
|
-
* The options to be passed to the Svelte compiler
|
|
422
|
+
* The options to be passed to the Svelte compiler. A few options are set by default,
|
|
423
|
+
* including `dev` and `css`. However, some options are non-configurable, like
|
|
424
|
+
* `filename`, `format`, `generate`, and `cssHash` (in dev).
|
|
405
425
|
*
|
|
406
426
|
* @see https://svelte.dev/docs#svelte_compile
|
|
407
427
|
*/
|
|
408
|
-
compilerOptions?: CompileOptions
|
|
428
|
+
compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
|
|
409
429
|
|
|
410
430
|
/**
|
|
411
431
|
* Handles warning emitted from the Svelte compiler
|