@sveltejs/vite-plugin-svelte 2.4.5 → 3.0.0-next.0
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/package.json +9 -9
- package/src/handle-hot-update.js +15 -5
- package/src/index.js +17 -103
- package/src/types/compile.d.ts +2 -2
- package/src/utils/compile.js +4 -17
- package/src/utils/constants.js +3 -8
- package/src/utils/dependencies.js +2 -2
- package/src/utils/esbuild.js +6 -8
- package/src/utils/hash.js +1 -1
- package/src/utils/id.js +2 -2
- package/src/utils/load-raw.js +4 -4
- package/src/utils/load-svelte-config.js +5 -5
- package/src/utils/log.js +11 -4
- package/src/utils/optimizer.js +2 -2
- package/src/utils/options.js +29 -8
- package/src/utils/preprocess.js +7 -3
- package/src/utils/sourcemaps.js +1 -1
- package/src/utils/vite-plugin-svelte-cache.js +2 -43
- package/src/utils/vite-plugin-svelte-stats.js +1 -1
- package/src/utils/watch.js +6 -4
- package/src/utils/resolve.js +0 -66
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-next.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"./package.json": "./package.json"
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": "^
|
|
19
|
+
"node": "^18.0.0 || >=20"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
@@ -37,20 +37,20 @@
|
|
|
37
37
|
"debug": "^4.3.4",
|
|
38
38
|
"deepmerge": "^4.3.1",
|
|
39
39
|
"kleur": "^4.1.5",
|
|
40
|
-
"magic-string": "^0.30.
|
|
40
|
+
"magic-string": "^0.30.3",
|
|
41
41
|
"svelte-hmr": "^0.15.3",
|
|
42
42
|
"vitefu": "^0.2.4",
|
|
43
|
-
"@sveltejs/vite-plugin-svelte-inspector": "^
|
|
43
|
+
"@sveltejs/vite-plugin-svelte-inspector": "^2.0.0-next.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"svelte": "^
|
|
47
|
-
"vite": "^
|
|
46
|
+
"svelte": "^4.0.0",
|
|
47
|
+
"vite": "^5.0.0-beta.1 || ^5.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/debug": "^4.1.8",
|
|
51
|
-
"esbuild": "^0.19.
|
|
52
|
-
"svelte": "^4.
|
|
53
|
-
"vite": "^
|
|
51
|
+
"esbuild": "^0.19.3",
|
|
52
|
+
"svelte": "^4.2.0",
|
|
53
|
+
"vite": "^5.0.0-beta.1"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"check:publint": "publint --strict",
|
package/src/handle-hot-update.js
CHANGED
|
@@ -14,7 +14,11 @@ import { toRollupError } from './utils/error.js';
|
|
|
14
14
|
export async function handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options) {
|
|
15
15
|
if (!cache.has(svelteRequest)) {
|
|
16
16
|
// file hasn't been requested yet (e.g. async component)
|
|
17
|
-
log.debug(
|
|
17
|
+
log.debug(
|
|
18
|
+
`handleHotUpdate called before initial transform for ${svelteRequest.id}`,
|
|
19
|
+
undefined,
|
|
20
|
+
'hmr'
|
|
21
|
+
);
|
|
18
22
|
return;
|
|
19
23
|
}
|
|
20
24
|
const { read, server, modules } = ctx;
|
|
@@ -39,7 +43,7 @@ export async function handleHotUpdate(compileSvelte, ctx, svelteRequest, cache,
|
|
|
39
43
|
if (cssIdx > -1) {
|
|
40
44
|
const cssUpdated = cssChanged(cachedCss, compileData.compiled.css);
|
|
41
45
|
if (!cssUpdated) {
|
|
42
|
-
log.debug(`skipping unchanged css for ${svelteRequest.cssId}
|
|
46
|
+
log.debug(`skipping unchanged css for ${svelteRequest.cssId}`, undefined, 'hmr');
|
|
43
47
|
affectedModules.splice(cssIdx, 1);
|
|
44
48
|
}
|
|
45
49
|
}
|
|
@@ -47,7 +51,7 @@ export async function handleHotUpdate(compileSvelte, ctx, svelteRequest, cache,
|
|
|
47
51
|
if (jsIdx > -1) {
|
|
48
52
|
const jsUpdated = jsChanged(cachedJS, compileData.compiled.js, svelteRequest.filename);
|
|
49
53
|
if (!jsUpdated) {
|
|
50
|
-
log.debug(`skipping unchanged js for ${svelteRequest.id}
|
|
54
|
+
log.debug(`skipping unchanged js for ${svelteRequest.id}`, undefined, 'hmr');
|
|
51
55
|
affectedModules.splice(jsIdx, 1);
|
|
52
56
|
// transform won't be called, log warnings here
|
|
53
57
|
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
@@ -57,14 +61,20 @@ export async function handleHotUpdate(compileSvelte, ctx, svelteRequest, cache,
|
|
|
57
61
|
// TODO is this enough? see also: https://github.com/vitejs/vite/issues/2274
|
|
58
62
|
const ssrModulesToInvalidate = affectedModules.filter((m) => !!m.ssrTransformResult);
|
|
59
63
|
if (ssrModulesToInvalidate.length > 0) {
|
|
60
|
-
log.debug(
|
|
64
|
+
log.debug(
|
|
65
|
+
`invalidating modules ${ssrModulesToInvalidate.map((m) => m.id).join(', ')}`,
|
|
66
|
+
undefined,
|
|
67
|
+
'hmr'
|
|
68
|
+
);
|
|
61
69
|
ssrModulesToInvalidate.forEach((moduleNode) => server.moduleGraph.invalidateModule(moduleNode));
|
|
62
70
|
}
|
|
63
71
|
if (affectedModules.length > 0) {
|
|
64
72
|
log.debug(
|
|
65
73
|
`handleHotUpdate for ${svelteRequest.id} result: ${affectedModules
|
|
66
74
|
.map((m) => m.id)
|
|
67
|
-
.join(', ')}
|
|
75
|
+
.join(', ')}`,
|
|
76
|
+
undefined,
|
|
77
|
+
'hmr'
|
|
68
78
|
);
|
|
69
79
|
}
|
|
70
80
|
return affectedModules;
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { version as viteVersion } from 'vite';
|
|
1
|
+
import fs from 'node:fs';
|
|
3
2
|
|
|
4
3
|
import { svelteInspector } from '@sveltejs/vite-plugin-svelte-inspector';
|
|
5
4
|
|
|
6
|
-
import { isDepExcluded } from 'vitefu';
|
|
7
5
|
import { handleHotUpdate } from './handle-hot-update.js';
|
|
8
6
|
import { log, logCompilerWarnings } from './utils/log.js';
|
|
9
7
|
import { createCompileSvelte } from './utils/compile.js';
|
|
@@ -17,16 +15,10 @@ import {
|
|
|
17
15
|
} from './utils/options.js';
|
|
18
16
|
|
|
19
17
|
import { ensureWatchedFile, setupWatchers } from './utils/watch.js';
|
|
20
|
-
import { resolveViaPackageJsonSvelte } from './utils/resolve.js';
|
|
21
|
-
|
|
22
18
|
import { toRollupError } from './utils/error.js';
|
|
23
19
|
import { saveSvelteMetadata } from './utils/optimizer.js';
|
|
24
20
|
import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache.js';
|
|
25
21
|
import { loadRaw } from './utils/load-raw.js';
|
|
26
|
-
import { FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE } from './utils/constants.js';
|
|
27
|
-
import { isSvelte3 } from './utils/svelte-version.js';
|
|
28
|
-
|
|
29
|
-
const isVite4_0 = viteVersion.startsWith('4.0');
|
|
30
22
|
|
|
31
23
|
/** @type {import('./index.d.ts').svelte} */
|
|
32
24
|
export function svelte(inlineOptions) {
|
|
@@ -42,15 +34,9 @@ export function svelte(inlineOptions) {
|
|
|
42
34
|
let options;
|
|
43
35
|
/** @type {import('vite').ResolvedConfig} */
|
|
44
36
|
let viteConfig;
|
|
45
|
-
|
|
46
37
|
/** @type {import('./types/compile.d.ts').CompileSvelte} */
|
|
47
38
|
let compileSvelte;
|
|
48
39
|
/* eslint-enable no-unused-vars */
|
|
49
|
-
|
|
50
|
-
/** @type {Promise<import('vite').Rollup.PartialResolvedId | null>} */
|
|
51
|
-
let resolvedSvelteSSR;
|
|
52
|
-
/** @type {Set<string>} */
|
|
53
|
-
let packagesWithResolveWarnings;
|
|
54
40
|
/** @type {import('./types/plugin-api.d.ts').PluginAPI} */
|
|
55
41
|
const api = {};
|
|
56
42
|
/** @type {import('vite').Plugin[]} */
|
|
@@ -71,7 +57,7 @@ export function svelte(inlineOptions) {
|
|
|
71
57
|
options = await preResolveOptions(inlineOptions, config, configEnv);
|
|
72
58
|
// extra vite config
|
|
73
59
|
const extraViteConfig = await buildExtraViteConfig(options, config);
|
|
74
|
-
log.debug('additional vite config', extraViteConfig);
|
|
60
|
+
log.debug('additional vite config', extraViteConfig, 'config');
|
|
75
61
|
return extraViteConfig;
|
|
76
62
|
},
|
|
77
63
|
|
|
@@ -83,11 +69,10 @@ export function svelte(inlineOptions) {
|
|
|
83
69
|
viteConfig = config;
|
|
84
70
|
// TODO deep clone to avoid mutability from outside?
|
|
85
71
|
api.options = options;
|
|
86
|
-
log.debug('resolved options', options);
|
|
72
|
+
log.debug('resolved options', options, 'config');
|
|
87
73
|
},
|
|
88
74
|
|
|
89
75
|
async buildStart() {
|
|
90
|
-
packagesWithResolveWarnings = new Set();
|
|
91
76
|
if (!options.prebundleSvelteLibraries) return;
|
|
92
77
|
const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
|
|
93
78
|
if (isSvelteMetadataChanged) {
|
|
@@ -108,18 +93,24 @@ export function svelte(inlineOptions) {
|
|
|
108
93
|
if (svelteRequest) {
|
|
109
94
|
const { filename, query, raw } = svelteRequest;
|
|
110
95
|
if (raw) {
|
|
111
|
-
|
|
96
|
+
const code = await loadRaw(svelteRequest, compileSvelte, options);
|
|
97
|
+
// prevent vite from injecting sourcemaps in the results.
|
|
98
|
+
return {
|
|
99
|
+
code,
|
|
100
|
+
map: {
|
|
101
|
+
mappings: ''
|
|
102
|
+
}
|
|
103
|
+
};
|
|
112
104
|
} else {
|
|
113
105
|
if (query.svelte && query.type === 'style') {
|
|
114
106
|
const css = cache.getCSS(svelteRequest);
|
|
115
107
|
if (css) {
|
|
116
|
-
log.debug(`load returns css for ${filename}`);
|
|
117
108
|
return css;
|
|
118
109
|
}
|
|
119
110
|
}
|
|
120
111
|
// prevent vite asset plugin from loading files as url that should be compiled in transform
|
|
121
112
|
if (viteConfig.assetsInclude(filename)) {
|
|
122
|
-
log.debug(`load returns raw content for ${filename}
|
|
113
|
+
log.debug(`load returns raw content for ${filename}`, undefined, 'load');
|
|
123
114
|
return fs.readFileSync(filename, 'utf-8');
|
|
124
115
|
}
|
|
125
116
|
}
|
|
@@ -133,78 +124,12 @@ export function svelte(inlineOptions) {
|
|
|
133
124
|
if (svelteRequest.query.type === 'style' && !svelteRequest.raw) {
|
|
134
125
|
// return cssId with root prefix so postcss pipeline of vite finds the directory correctly
|
|
135
126
|
// see https://github.com/sveltejs/vite-plugin-svelte/issues/14
|
|
136
|
-
log.debug(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// TODO: remove this after bumping peerDep on Vite to 4.1+ or Svelte to 4.0+
|
|
142
|
-
if (isVite4_0 && isSvelte3 && ssr && importee === 'svelte') {
|
|
143
|
-
if (!resolvedSvelteSSR) {
|
|
144
|
-
resolvedSvelteSSR = this.resolve('svelte/ssr', undefined, { skipSelf: true }).then(
|
|
145
|
-
(svelteSSR) => {
|
|
146
|
-
log.debug('resolved svelte to svelte/ssr');
|
|
147
|
-
return svelteSSR;
|
|
148
|
-
},
|
|
149
|
-
(err) => {
|
|
150
|
-
log.debug(
|
|
151
|
-
'failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it',
|
|
152
|
-
err
|
|
153
|
-
);
|
|
154
|
-
return null; // returning null here leads to svelte getting resolved regularly
|
|
155
|
-
}
|
|
127
|
+
log.debug(
|
|
128
|
+
`resolveId resolved virtual css module ${svelteRequest.cssId}`,
|
|
129
|
+
undefined,
|
|
130
|
+
'resolve'
|
|
156
131
|
);
|
|
157
|
-
|
|
158
|
-
return resolvedSvelteSSR;
|
|
159
|
-
}
|
|
160
|
-
//@ts-expect-error scan
|
|
161
|
-
const scan = !!opts?.scan; // scanner phase of optimizeDeps
|
|
162
|
-
const isPrebundled =
|
|
163
|
-
options.prebundleSvelteLibraries &&
|
|
164
|
-
viteConfig.optimizeDeps?.disabled !== true &&
|
|
165
|
-
viteConfig.optimizeDeps?.disabled !== (options.isBuild ? 'build' : 'dev') &&
|
|
166
|
-
!isDepExcluded(importee, viteConfig.optimizeDeps?.exclude ?? []);
|
|
167
|
-
// for prebundled libraries we let vite resolve the prebundling result
|
|
168
|
-
// for ssr, during scanning and non-prebundled, we do it
|
|
169
|
-
if (ssr || scan || !isPrebundled) {
|
|
170
|
-
try {
|
|
171
|
-
const isFirstResolve = !cache.hasResolvedSvelteField(importee, importer);
|
|
172
|
-
const resolved = await resolveViaPackageJsonSvelte(importee, importer, cache);
|
|
173
|
-
if (isFirstResolve && resolved) {
|
|
174
|
-
const packageInfo = await cache.getPackageInfo(resolved);
|
|
175
|
-
const packageVersion = `${packageInfo.name}@${packageInfo.version}`;
|
|
176
|
-
log.debug.once(
|
|
177
|
-
`resolveId resolved ${importee} to ${resolved} via package.json svelte field of ${packageVersion}`
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
try {
|
|
181
|
-
const viteResolved = (
|
|
182
|
-
await this.resolve(importee, importer, { ...opts, skipSelf: true })
|
|
183
|
-
)?.id;
|
|
184
|
-
if (resolved !== viteResolved) {
|
|
185
|
-
packagesWithResolveWarnings.add(packageVersion);
|
|
186
|
-
log.debug.enabled &&
|
|
187
|
-
log.debug.once(
|
|
188
|
-
`resolve difference for ${packageVersion} ${importee} - svelte: "${resolved}", vite: "${viteResolved}"`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
} catch (e) {
|
|
192
|
-
packagesWithResolveWarnings.add(packageVersion);
|
|
193
|
-
log.debug.enabled &&
|
|
194
|
-
log.debug.once(
|
|
195
|
-
`resolve error for ${packageVersion} ${importee} - svelte: "${resolved}", vite: ERROR`,
|
|
196
|
-
e
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return resolved;
|
|
201
|
-
} catch (e) {
|
|
202
|
-
log.debug.once(
|
|
203
|
-
`error trying to resolve ${importee} from ${importer} via package.json svelte field `,
|
|
204
|
-
e
|
|
205
|
-
);
|
|
206
|
-
// this error most likely happens due to non-svelte related importee/importers so swallow it here
|
|
207
|
-
// in case it really way a svelte library, users will notice anyway. (lib not working due to failed resolve)
|
|
132
|
+
return svelteRequest.cssId;
|
|
208
133
|
}
|
|
209
134
|
}
|
|
210
135
|
},
|
|
@@ -235,7 +160,6 @@ export function svelte(inlineOptions) {
|
|
|
235
160
|
}
|
|
236
161
|
}
|
|
237
162
|
}
|
|
238
|
-
log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
|
|
239
163
|
return {
|
|
240
164
|
...compileData.compiled.js,
|
|
241
165
|
meta: {
|
|
@@ -257,16 +181,6 @@ export function svelte(inlineOptions) {
|
|
|
257
181
|
},
|
|
258
182
|
async buildEnd() {
|
|
259
183
|
await options.stats?.finishAll();
|
|
260
|
-
if (
|
|
261
|
-
!options.experimental?.disableSvelteResolveWarnings &&
|
|
262
|
-
packagesWithResolveWarnings?.size > 0
|
|
263
|
-
) {
|
|
264
|
-
log.warn(
|
|
265
|
-
`WARNING: The following packages use a svelte resolve configuration in package.json that has conflicting results and is going to cause problems future.\n\n${[
|
|
266
|
-
...packagesWithResolveWarnings
|
|
267
|
-
].join('\n')}\n\nPlease see ${FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE} for details.`
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
184
|
}
|
|
271
185
|
},
|
|
272
186
|
svelteInspector()
|
package/src/types/compile.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface Compiled {
|
|
|
19
19
|
css: Code;
|
|
20
20
|
ast: any; // TODO type
|
|
21
21
|
warnings: any[]; // TODO type
|
|
22
|
-
vars: {
|
|
22
|
+
vars: Array<{
|
|
23
23
|
name: string;
|
|
24
24
|
export_name: string;
|
|
25
25
|
injected: boolean;
|
|
@@ -29,7 +29,7 @@ export interface Compiled {
|
|
|
29
29
|
referenced: boolean;
|
|
30
30
|
writable: boolean;
|
|
31
31
|
referenced_from_script: boolean;
|
|
32
|
-
}
|
|
32
|
+
}>;
|
|
33
33
|
stats: {
|
|
34
34
|
timings: {
|
|
35
35
|
total: number;
|
package/src/utils/compile.js
CHANGED
|
@@ -9,8 +9,6 @@ import { mapToRelative } from './sourcemaps.js';
|
|
|
9
9
|
|
|
10
10
|
const scriptLangRE = /<script [^>]*lang=["']?([^"' >]+)["']?[^>]*>/;
|
|
11
11
|
|
|
12
|
-
import { isSvelte3 } from './svelte-version.js';
|
|
13
|
-
|
|
14
12
|
/**
|
|
15
13
|
* @param {Function} [makeHot]
|
|
16
14
|
* @returns {import('../types/compile.d.ts').CompileSvelte}
|
|
@@ -55,13 +53,9 @@ export const _createCompileSvelte = (makeHot) => {
|
|
|
55
53
|
filename,
|
|
56
54
|
generate: ssr ? 'ssr' : 'dom'
|
|
57
55
|
};
|
|
58
|
-
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
compileOptions.format = 'esm';
|
|
61
|
-
}
|
|
56
|
+
|
|
62
57
|
if (options.hot && options.emitCss) {
|
|
63
58
|
const hash = `s-${safeBase64Hash(normalizedFilename)}`;
|
|
64
|
-
log.debug(`setting cssHash ${hash} for ${normalizedFilename}`);
|
|
65
59
|
compileOptions.cssHash = () => hash;
|
|
66
60
|
}
|
|
67
61
|
if (ssr && compileOptions.enableSourcemap !== false) {
|
|
@@ -112,7 +106,9 @@ export const _createCompileSvelte = (makeHot) => {
|
|
|
112
106
|
});
|
|
113
107
|
if (dynamicCompileOptions && log.debug.enabled) {
|
|
114
108
|
log.debug(
|
|
115
|
-
`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}
|
|
109
|
+
`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`,
|
|
110
|
+
undefined,
|
|
111
|
+
'compile'
|
|
116
112
|
);
|
|
117
113
|
}
|
|
118
114
|
const finalCompileOptions = dynamicCompileOptions
|
|
@@ -125,15 +121,6 @@ export const _createCompileSvelte = (makeHot) => {
|
|
|
125
121
|
const endStat = stats?.start(filename);
|
|
126
122
|
const compiled = compile(finalCode, finalCompileOptions);
|
|
127
123
|
|
|
128
|
-
if (isSvelte3) {
|
|
129
|
-
// prevent dangling pure comments
|
|
130
|
-
// see https://github.com/sveltejs/kit/issues/9492#issuecomment-1487704985
|
|
131
|
-
// uses regex replace with whitespace to keep sourcemap/character count unmodified
|
|
132
|
-
compiled.js.code = compiled.js.code.replace(
|
|
133
|
-
/\/\* [@#]__PURE__ \*\/(\s*)$/gm,
|
|
134
|
-
' $1'
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
124
|
if (endStat) {
|
|
138
125
|
endStat();
|
|
139
126
|
}
|
package/src/utils/constants.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { isSvelte3 } from './svelte-version.js';
|
|
2
|
-
|
|
3
1
|
export const VITE_RESOLVE_MAIN_FIELDS = ['module', 'jsnext:main', 'jsnext'];
|
|
4
2
|
|
|
5
3
|
export const SVELTE_RESOLVE_MAIN_FIELDS = ['svelte'];
|
|
@@ -8,16 +6,13 @@ export const SVELTE_IMPORTS = [
|
|
|
8
6
|
'svelte/animate',
|
|
9
7
|
'svelte/easing',
|
|
10
8
|
'svelte/internal',
|
|
9
|
+
'svelte/internal/disclose-version',
|
|
11
10
|
'svelte/motion',
|
|
12
11
|
'svelte/ssr',
|
|
13
12
|
'svelte/store',
|
|
14
13
|
'svelte/transition',
|
|
15
14
|
'svelte'
|
|
16
15
|
];
|
|
17
|
-
// TODO add to global list after dropping svelte 3
|
|
18
|
-
if (!isSvelte3) {
|
|
19
|
-
SVELTE_IMPORTS.push('svelte/internal/disclose-version');
|
|
20
|
-
}
|
|
21
16
|
|
|
22
17
|
export const SVELTE_HMR_IMPORTS = [
|
|
23
18
|
'svelte-hmr/runtime/hot-api-esm.js',
|
|
@@ -27,5 +22,5 @@ export const SVELTE_HMR_IMPORTS = [
|
|
|
27
22
|
|
|
28
23
|
export const SVELTE_EXPORT_CONDITIONS = ['svelte'];
|
|
29
24
|
|
|
30
|
-
export const
|
|
31
|
-
'https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#
|
|
25
|
+
export const FAQ_LINK_MISSING_EXPORTS_CONDITION =
|
|
26
|
+
'https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#missing-exports-condition';
|
package/src/utils/esbuild.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { compile, preprocess } from 'svelte/compiler';
|
|
3
3
|
import { log } from './log.js';
|
|
4
4
|
import { toESBuildError } from './error.js';
|
|
5
|
-
import { isSvelte3 } from './svelte-version.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* @typedef {NonNullable<import('vite').DepOptimizationOptions['esbuildOptions']>} EsbuildOptions
|
|
@@ -24,7 +23,7 @@ export function esbuildSveltePlugin(options) {
|
|
|
24
23
|
if (build.initialOptions.plugins?.some((v) => v.name === 'vite:dep-scan')) return;
|
|
25
24
|
|
|
26
25
|
const svelteExtensions = (options.extensions ?? ['.svelte']).map((ext) => ext.slice(1));
|
|
27
|
-
const svelteFilter = new RegExp(
|
|
26
|
+
const svelteFilter = new RegExp('\\.(' + svelteExtensions.join('|') + ')(\\?.*)?$');
|
|
28
27
|
/** @type {import('../types/vite-plugin-svelte-stats.d.ts').StatCollection | undefined} */
|
|
29
28
|
let statsCollection;
|
|
30
29
|
build.onStart(() => {
|
|
@@ -67,10 +66,7 @@ async function compileSvelte(options, { filename, code }, statsCollection) {
|
|
|
67
66
|
filename,
|
|
68
67
|
generate: 'dom'
|
|
69
68
|
};
|
|
70
|
-
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
compileOptions.format = 'esm';
|
|
73
|
-
}
|
|
69
|
+
|
|
74
70
|
let preprocessed;
|
|
75
71
|
|
|
76
72
|
if (options.preprocess) {
|
|
@@ -106,5 +102,7 @@ async function compileSvelte(options, { filename, code }, statsCollection) {
|
|
|
106
102
|
if (endStat) {
|
|
107
103
|
endStat();
|
|
108
104
|
}
|
|
109
|
-
return compiled.js.
|
|
105
|
+
return compiled.js.map
|
|
106
|
+
? compiled.js.code + '//# sourceMappingURL=' + compiled.js.map.toUrl()
|
|
107
|
+
: compiled.js.code;
|
|
110
108
|
}
|
package/src/utils/hash.js
CHANGED
package/src/utils/id.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createFilter, normalizePath } from 'vite';
|
|
2
|
-
import * as fs from 'fs';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
3
|
import { log } from './log.js';
|
|
4
4
|
|
|
5
5
|
const VITE_FS_PREFIX = '/@fs/';
|
|
@@ -21,7 +21,7 @@ const TYPES_WITH_COMPILER_OPTIONS = ['style', 'script', 'all'];
|
|
|
21
21
|
* @returns {{ filename: string, rawQuery: string }}
|
|
22
22
|
*/
|
|
23
23
|
function splitId(id) {
|
|
24
|
-
const parts = id.split(
|
|
24
|
+
const parts = id.split('?', 2);
|
|
25
25
|
const filename = parts[0];
|
|
26
26
|
const rawQuery = parts[1];
|
|
27
27
|
return { filename, rawQuery };
|
package/src/utils/load-raw.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
2
|
import { toRollupError } from './error.js';
|
|
3
3
|
import { log } from './log.js';
|
|
4
4
|
|
|
@@ -64,7 +64,7 @@ export async function loadRaw(svelteRequest, compileSvelte, options) {
|
|
|
64
64
|
}" combined with direct in ${id}. supported are: ${supportedDirectTypes.join(', ')}`
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
|
-
log.debug(`load returns direct result for ${id}
|
|
67
|
+
log.debug(`load returns direct result for ${id}`, undefined, 'load');
|
|
68
68
|
let directOutput = result.code;
|
|
69
69
|
if (query.sourcemap && result.map?.toUrl) {
|
|
70
70
|
const map = `sourceMappingURL=${result.map.toUrl()}`;
|
|
@@ -76,7 +76,7 @@ export async function loadRaw(svelteRequest, compileSvelte, options) {
|
|
|
76
76
|
}
|
|
77
77
|
return directOutput;
|
|
78
78
|
} else if (query.raw) {
|
|
79
|
-
log.debug(`load returns raw result for ${id}
|
|
79
|
+
log.debug(`load returns raw result for ${id}`, undefined, 'load');
|
|
80
80
|
return toRawExports(result);
|
|
81
81
|
} else {
|
|
82
82
|
throw new Error(`invalid raw mode in ${id}, supported are raw, direct`);
|
|
@@ -126,7 +126,7 @@ function toRawExports(object) {
|
|
|
126
126
|
.map(([key, value]) => `export const ${key}=${JSON.stringify(value)}`)
|
|
127
127
|
.join('\n') + '\n';
|
|
128
128
|
if (Object.prototype.hasOwnProperty.call(object, 'code')) {
|
|
129
|
-
exports +=
|
|
129
|
+
exports += 'export default code\n';
|
|
130
130
|
}
|
|
131
131
|
return exports;
|
|
132
132
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { pathToFileURL } from 'url';
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import { log } from './log.js';
|
|
6
6
|
|
|
7
7
|
// used to require cjs config in esm.
|
|
@@ -104,7 +104,7 @@ function findConfigToLoad(viteConfig, inlineOptions) {
|
|
|
104
104
|
.map((candidate) => path.resolve(root, candidate))
|
|
105
105
|
.filter((file) => fs.existsSync(file));
|
|
106
106
|
if (existingKnownConfigFiles.length === 0) {
|
|
107
|
-
log.debug(`no svelte config found at ${root}
|
|
107
|
+
log.debug(`no svelte config found at ${root}`, undefined, 'config');
|
|
108
108
|
return;
|
|
109
109
|
} else if (existingKnownConfigFiles.length > 1) {
|
|
110
110
|
log.warn(
|
package/src/utils/log.js
CHANGED
|
@@ -8,7 +8,7 @@ const prefix = 'vite-plugin-svelte';
|
|
|
8
8
|
/** @type {Record<import('../types/log.d.ts').LogLevel, any>} */
|
|
9
9
|
const loggers = {
|
|
10
10
|
debug: {
|
|
11
|
-
log: debug(
|
|
11
|
+
log: debug(`${prefix}`),
|
|
12
12
|
enabled: false,
|
|
13
13
|
isDebug: true
|
|
14
14
|
},
|
|
@@ -65,7 +65,13 @@ function _log(logger, message, payload, namespace) {
|
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
if (logger.isDebug) {
|
|
68
|
-
|
|
68
|
+
let log = logger.log;
|
|
69
|
+
if (namespace) {
|
|
70
|
+
if (!isDebugNamespaceEnabled(namespace)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
log = logger.log.extend(namespace);
|
|
74
|
+
}
|
|
69
75
|
payload !== undefined ? log(message, payload) : log(message);
|
|
70
76
|
} else {
|
|
71
77
|
logger.log(
|
|
@@ -204,7 +210,8 @@ function buildExtraWarnings(warnings, isBuild) {
|
|
|
204
210
|
extraWarnings.push({
|
|
205
211
|
...noScopableElementWarning,
|
|
206
212
|
code: 'vite-plugin-svelte-css-no-scopable-elements',
|
|
207
|
-
message:
|
|
213
|
+
message:
|
|
214
|
+
"No scopable elements found in template. If you're using global styles in the style tag, you should move it into an external stylesheet file and import it in JS. See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#where-should-i-put-my-global-styles."
|
|
208
215
|
});
|
|
209
216
|
}
|
|
210
217
|
}
|
|
@@ -250,5 +257,5 @@ export function buildExtendedLogMessage(w) {
|
|
|
250
257
|
* @returns {boolean}
|
|
251
258
|
*/
|
|
252
259
|
export function isDebugNamespaceEnabled(namespace) {
|
|
253
|
-
return debug.enabled(
|
|
260
|
+
return debug.enabled(`${prefix}:${namespace}`);
|
|
254
261
|
}
|
package/src/utils/optimizer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import path from 'path';
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
// List of options that changes the prebundling result
|
|
5
5
|
/** @type {(keyof import('../types/options.d.ts').ResolvedOptions)[]} */
|
package/src/utils/options.js
CHANGED
|
@@ -3,6 +3,7 @@ import { normalizePath } from 'vite';
|
|
|
3
3
|
import { isDebugNamespaceEnabled, log } from './log.js';
|
|
4
4
|
import { loadSvelteConfig } from './load-svelte-config.js';
|
|
5
5
|
import {
|
|
6
|
+
FAQ_LINK_MISSING_EXPORTS_CONDITION,
|
|
6
7
|
SVELTE_EXPORT_CONDITIONS,
|
|
7
8
|
SVELTE_HMR_IMPORTS,
|
|
8
9
|
SVELTE_IMPORTS,
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
VITE_RESOLVE_MAIN_FIELDS
|
|
11
12
|
} from './constants.js';
|
|
12
13
|
|
|
13
|
-
import path from 'path';
|
|
14
|
+
import path from 'node:path';
|
|
14
15
|
import { esbuildSveltePlugin, facadeEsbuildSveltePluginName } from './esbuild.js';
|
|
15
16
|
import { addExtraPreprocessors } from './preprocess.js';
|
|
16
17
|
import deepmerge from 'deepmerge';
|
|
@@ -428,7 +429,7 @@ export async function buildExtraViteConfig(options, config) {
|
|
|
428
429
|
(options.hot && options.hot.partialAccept !== false)) && // deviate from svelte-hmr, default to true
|
|
429
430
|
config.experimental?.hmrPartialAccept !== false
|
|
430
431
|
) {
|
|
431
|
-
log.debug('enabling "experimental.hmrPartialAccept" in vite config');
|
|
432
|
+
log.debug('enabling "experimental.hmrPartialAccept" in vite config', undefined, 'config');
|
|
432
433
|
extraViteConfig.experimental = { hmrPartialAccept: true };
|
|
433
434
|
}
|
|
434
435
|
validateViteConfig(extraViteConfig, config, options);
|
|
@@ -481,6 +482,7 @@ function validateViteConfig(extraViteConfig, config, options) {
|
|
|
481
482
|
*/
|
|
482
483
|
async function buildExtraConfigForDependencies(options, config) {
|
|
483
484
|
// extra handling for svelte dependencies in the project
|
|
485
|
+
const packagesWithoutSvelteExportsCondition = new Set();
|
|
484
486
|
const depsConfig = await crawlFrameworkPkgs({
|
|
485
487
|
root: options.root,
|
|
486
488
|
isBuild: options.isBuild,
|
|
@@ -496,7 +498,11 @@ async function buildExtraConfigForDependencies(options, config) {
|
|
|
496
498
|
return value;
|
|
497
499
|
});
|
|
498
500
|
}
|
|
499
|
-
|
|
501
|
+
const hasSvelteField = !!pkgJson.svelte;
|
|
502
|
+
if (hasSvelteField && !hasSvelteCondition) {
|
|
503
|
+
packagesWithoutSvelteExportsCondition.add(`${pkgJson.name}@${pkgJson.version}`);
|
|
504
|
+
}
|
|
505
|
+
return hasSvelteCondition || hasSvelteField;
|
|
500
506
|
},
|
|
501
507
|
isSemiFrameworkPkgByJson(pkgJson) {
|
|
502
508
|
return !!pkgJson.dependencies?.svelte || !!pkgJson.peerDependencies?.svelte;
|
|
@@ -510,8 +516,17 @@ async function buildExtraConfigForDependencies(options, config) {
|
|
|
510
516
|
}
|
|
511
517
|
}
|
|
512
518
|
});
|
|
513
|
-
|
|
514
|
-
|
|
519
|
+
if (
|
|
520
|
+
!options.experimental?.disableSvelteResolveWarnings &&
|
|
521
|
+
packagesWithoutSvelteExportsCondition?.size > 0
|
|
522
|
+
) {
|
|
523
|
+
log.warn(
|
|
524
|
+
`WARNING: The following packages have a svelte field in their package.json but no exports condition for svelte.\n\n${[
|
|
525
|
+
...packagesWithoutSvelteExportsCondition
|
|
526
|
+
].join('\n')}\n\nPlease see ${FAQ_LINK_MISSING_EXPORTS_CONDITION} for details.`
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
log.debug('extra config for dependencies generated by vitefu', depsConfig, 'config');
|
|
515
530
|
|
|
516
531
|
if (options.prebundleSvelteLibraries) {
|
|
517
532
|
// prebundling enabled, so we don't need extra dependency excludes
|
|
@@ -545,7 +560,7 @@ async function buildExtraConfigForDependencies(options, config) {
|
|
|
545
560
|
});
|
|
546
561
|
}
|
|
547
562
|
|
|
548
|
-
log.debug('post-processed extra config for dependencies', depsConfig);
|
|
563
|
+
log.debug('post-processed extra config for dependencies', depsConfig, 'config');
|
|
549
564
|
|
|
550
565
|
return depsConfig;
|
|
551
566
|
}
|
|
@@ -562,11 +577,17 @@ function buildExtraConfigForSvelte(config) {
|
|
|
562
577
|
if (!isDepExcluded('svelte', config.optimizeDeps?.exclude ?? [])) {
|
|
563
578
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== 'svelte/ssr'); // not used on clientside
|
|
564
579
|
log.debug(
|
|
565
|
-
`adding bare svelte packages to optimizeDeps.include: ${svelteImportsToInclude.join(', ')}
|
|
580
|
+
`adding bare svelte packages to optimizeDeps.include: ${svelteImportsToInclude.join(', ')} `,
|
|
581
|
+
undefined,
|
|
582
|
+
'config'
|
|
566
583
|
);
|
|
567
584
|
include.push(...svelteImportsToInclude);
|
|
568
585
|
} else {
|
|
569
|
-
log.debug(
|
|
586
|
+
log.debug(
|
|
587
|
+
'"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.',
|
|
588
|
+
undefined,
|
|
589
|
+
'config'
|
|
590
|
+
);
|
|
570
591
|
}
|
|
571
592
|
/** @type {(string | RegExp)[]} */
|
|
572
593
|
const noExternal = [];
|
package/src/utils/preprocess.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import MagicString from 'magic-string';
|
|
2
2
|
import { log } from './log.js';
|
|
3
|
-
import path from 'path';
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* this appends a *{} rule to component styles to force the svelte compiler to add style classes to all nodes
|
|
@@ -84,14 +84,18 @@ function buildExtraPreprocessors(options, config) {
|
|
|
84
84
|
log.debug(
|
|
85
85
|
`Ignoring svelte preprocessors defined by these vite plugins: ${ignored
|
|
86
86
|
.map((p) => p.name)
|
|
87
|
-
.join(', ')}
|
|
87
|
+
.join(', ')}`,
|
|
88
|
+
undefined,
|
|
89
|
+
'preprocess'
|
|
88
90
|
);
|
|
89
91
|
}
|
|
90
92
|
if (included.length > 0) {
|
|
91
93
|
log.debug(
|
|
92
94
|
`Adding svelte preprocessors defined by these vite plugins: ${included
|
|
93
95
|
.map((p) => p.name)
|
|
94
|
-
.join(', ')}
|
|
96
|
+
.join(', ')}`,
|
|
97
|
+
undefined,
|
|
98
|
+
'preprocess'
|
|
95
99
|
);
|
|
96
100
|
appendPreprocessors.push(...pluginsWithPreprocessors.map((p) => p.api.sveltePreprocess));
|
|
97
101
|
}
|
package/src/utils/sourcemaps.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { dirname } from 'path';
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
3
|
import { findClosestPkgJsonPath } from 'vitefu';
|
|
4
4
|
import { normalizePath } from 'vite';
|
|
5
5
|
|
|
@@ -24,8 +24,6 @@ export class VitePluginSvelteCache {
|
|
|
24
24
|
#dependencies = new Map();
|
|
25
25
|
/** @type {Map<string, Set<string>>} */
|
|
26
26
|
#dependants = new Map();
|
|
27
|
-
/** @type {Map<string, string>} */
|
|
28
|
-
#resolvedSvelteFields = new Map();
|
|
29
27
|
/** @type {Map<string, any>} */
|
|
30
28
|
#errors = new Map();
|
|
31
29
|
/** @type {PackageInfo[]} */
|
|
@@ -168,45 +166,6 @@ export class VitePluginSvelteCache {
|
|
|
168
166
|
return dependants ? [...dependants] : [];
|
|
169
167
|
}
|
|
170
168
|
|
|
171
|
-
/**
|
|
172
|
-
* @param {string} name
|
|
173
|
-
* @param {string} [importer]
|
|
174
|
-
* @returns {string|void}
|
|
175
|
-
*/
|
|
176
|
-
getResolvedSvelteField(name, importer) {
|
|
177
|
-
return this.#resolvedSvelteFields.get(this.#getResolvedSvelteFieldKey(name, importer));
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @param {string} name
|
|
182
|
-
* @param {string} [importer]
|
|
183
|
-
* @returns {boolean}
|
|
184
|
-
*/
|
|
185
|
-
hasResolvedSvelteField(name, importer) {
|
|
186
|
-
return this.#resolvedSvelteFields.has(this.#getResolvedSvelteFieldKey(name, importer));
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
*
|
|
190
|
-
* @param {string} importee
|
|
191
|
-
* @param {string | undefined} importer
|
|
192
|
-
* @param {string} resolvedSvelte
|
|
193
|
-
*/
|
|
194
|
-
setResolvedSvelteField(importee, importer, resolvedSvelte) {
|
|
195
|
-
this.#resolvedSvelteFields.set(
|
|
196
|
-
this.#getResolvedSvelteFieldKey(importee, importer),
|
|
197
|
-
resolvedSvelte
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* @param {string} importee
|
|
203
|
-
* @param {string | undefined} importer
|
|
204
|
-
* @returns {string}
|
|
205
|
-
*/
|
|
206
|
-
#getResolvedSvelteFieldKey(importee, importer) {
|
|
207
|
-
return importer ? `${importer} > ${importee}` : importee;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
169
|
/**
|
|
211
170
|
* @param {string} file
|
|
212
171
|
* @returns {Promise<PackageInfo>}
|
package/src/utils/watch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
2
|
import { log } from './log.js';
|
|
3
3
|
import { knownSvelteConfigNames } from './load-svelte-config.js';
|
|
4
|
-
import path from 'path';
|
|
4
|
+
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {import('../types/options.d.ts').ResolvedOptions} options
|
|
@@ -22,7 +22,9 @@ export function setupWatchers(options, cache, requestParser) {
|
|
|
22
22
|
dependants.forEach((dependant) => {
|
|
23
23
|
if (fs.existsSync(dependant)) {
|
|
24
24
|
log.debug(
|
|
25
|
-
`emitting virtual change event for "${dependant}" because depdendency "${filename}" changed
|
|
25
|
+
`emitting virtual change event for "${dependant}" because depdendency "${filename}" changed`,
|
|
26
|
+
undefined,
|
|
27
|
+
'hmr'
|
|
26
28
|
);
|
|
27
29
|
watcher.emit('change', dependant);
|
|
28
30
|
}
|
|
@@ -34,7 +36,7 @@ export function setupWatchers(options, cache, requestParser) {
|
|
|
34
36
|
if (svelteRequest) {
|
|
35
37
|
const removedFromCache = cache.remove(svelteRequest);
|
|
36
38
|
if (removedFromCache) {
|
|
37
|
-
log.debug(`cleared VitePluginSvelteCache for deleted file ${filename}
|
|
39
|
+
log.debug(`cleared VitePluginSvelteCache for deleted file ${filename}`, undefined, 'hmr');
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
};
|
package/src/utils/resolve.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { builtinModules } from 'module';
|
|
3
|
-
import { resolveDependencyData, isCommonDepWithoutSvelteField } from './dependencies.js';
|
|
4
|
-
import { normalizePath } from 'vite';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @param {string} importee
|
|
8
|
-
* @param {string | undefined} importer
|
|
9
|
-
* @param {import('./vite-plugin-svelte-cache').VitePluginSvelteCache} cache
|
|
10
|
-
* @returns {Promise<string | void>}
|
|
11
|
-
*/
|
|
12
|
-
export async function resolveViaPackageJsonSvelte(importee, importer, cache) {
|
|
13
|
-
if (
|
|
14
|
-
importer &&
|
|
15
|
-
isBareImport(importee) &&
|
|
16
|
-
!isNodeInternal(importee) &&
|
|
17
|
-
!isCommonDepWithoutSvelteField(importee)
|
|
18
|
-
) {
|
|
19
|
-
const cached = cache.getResolvedSvelteField(importee, importer);
|
|
20
|
-
if (cached) {
|
|
21
|
-
return cached;
|
|
22
|
-
}
|
|
23
|
-
const pkgData = await resolveDependencyData(importee, importer);
|
|
24
|
-
if (pkgData) {
|
|
25
|
-
const { pkg, dir } = pkgData;
|
|
26
|
-
if (pkg.svelte) {
|
|
27
|
-
const result = normalizePath(path.resolve(dir, pkg.svelte));
|
|
28
|
-
cache.setResolvedSvelteField(importee, importer, result);
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @param {string} importee
|
|
37
|
-
* @returns {boolean}
|
|
38
|
-
*/
|
|
39
|
-
function isNodeInternal(importee) {
|
|
40
|
-
return importee.startsWith('node:') || builtinModules.includes(importee);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param {string} importee
|
|
45
|
-
* @returns {boolean}
|
|
46
|
-
*/
|
|
47
|
-
function isBareImport(importee) {
|
|
48
|
-
if (
|
|
49
|
-
!importee ||
|
|
50
|
-
importee[0] === '.' ||
|
|
51
|
-
importee[0] === '\0' ||
|
|
52
|
-
importee.includes(':') ||
|
|
53
|
-
path.isAbsolute(importee)
|
|
54
|
-
) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
const parts = importee.split('/');
|
|
58
|
-
switch (parts.length) {
|
|
59
|
-
case 1:
|
|
60
|
-
return true;
|
|
61
|
-
case 2:
|
|
62
|
-
return parts[0].startsWith('@');
|
|
63
|
-
default:
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|