svelte-bun 0.1.0 → 0.1.1
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/compile.d.ts +0 -5
- package/package.json +1 -1
- package/src/component.ts +0 -5
- package/src/esm-env.ts +0 -5
- package/src/index.ts +11 -4
- package/src/register.ts +0 -2
- package/src/resolve.ts +1 -1
package/compile.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** What `compileFile` returns. */
|
|
2
1
|
export type CompiledFile = {
|
|
3
2
|
js: string;
|
|
4
3
|
/** Svelte's warnings, each as `file:line:column message`. */
|
|
@@ -6,12 +5,10 @@ export type CompiledFile = {
|
|
|
6
5
|
/** Set with `css: "external"` when the component has a `<style>`. */
|
|
7
6
|
css?: string;
|
|
8
7
|
};
|
|
9
|
-
/** Options for `compileFile`. */
|
|
10
8
|
export type CompileFileOptions = {
|
|
11
9
|
/** The name Svelte's warnings and scoped-CSS hashes use. */
|
|
12
10
|
filename: string;
|
|
13
11
|
side: Side;
|
|
14
|
-
/** Whether Svelte compiles in its development checks. */
|
|
15
12
|
dev?: boolean;
|
|
16
13
|
/**
|
|
17
14
|
* Whether to compile in Svelte's HMR, client side only; the host provides
|
|
@@ -27,7 +24,6 @@ export type CompileFileOptions = {
|
|
|
27
24
|
/** Passed to Svelte's `compile()`; the options above win. */
|
|
28
25
|
compilerOptions?: Readonly<Record<string, unknown>>;
|
|
29
26
|
};
|
|
30
|
-
/** Which output Svelte generates. */
|
|
31
27
|
export type Side = "client" | "server";
|
|
32
28
|
/** The parts of `svelte/compiler` svelte-bun calls. */
|
|
33
29
|
export type SvelteCompiler = {
|
|
@@ -52,7 +48,6 @@ export type SvelteCompiler = {
|
|
|
52
48
|
code: string;
|
|
53
49
|
}>;
|
|
54
50
|
};
|
|
55
|
-
/** The parts of a Svelte warning svelte-bun reports. */
|
|
56
51
|
export type SvelteWarning = {
|
|
57
52
|
message: string;
|
|
58
53
|
start?: {
|
package/package.json
CHANGED
package/src/component.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Which output Svelte generates. */
|
|
2
1
|
export type Side = "client" | "server";
|
|
3
2
|
|
|
4
3
|
/** The parts of `svelte/compiler` svelte-bun calls. */
|
|
@@ -22,12 +21,10 @@ export type SvelteCompiler = {
|
|
|
22
21
|
): Promise<{ code: string }>;
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
/** Options for `compileFile`. */
|
|
26
24
|
export type CompileFileOptions = {
|
|
27
25
|
/** The name Svelte's warnings and scoped-CSS hashes use. */
|
|
28
26
|
filename: string;
|
|
29
27
|
side: Side;
|
|
30
|
-
/** Whether Svelte compiles in its development checks. */
|
|
31
28
|
dev?: boolean;
|
|
32
29
|
/**
|
|
33
30
|
* Whether to compile in Svelte's HMR, client side only; the host provides
|
|
@@ -44,13 +41,11 @@ export type CompileFileOptions = {
|
|
|
44
41
|
compilerOptions?: Readonly<Record<string, unknown>>;
|
|
45
42
|
};
|
|
46
43
|
|
|
47
|
-
/** The parts of a Svelte warning svelte-bun reports. */
|
|
48
44
|
export type SvelteWarning = {
|
|
49
45
|
message: string;
|
|
50
46
|
start?: { line: number; column: number };
|
|
51
47
|
};
|
|
52
48
|
|
|
53
|
-
/** What `compileFile` returns. */
|
|
54
49
|
export type CompiledFile = {
|
|
55
50
|
js: string;
|
|
56
51
|
/** Svelte's warnings, each as `file:line:column message`. */
|
package/src/esm-env.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
const ESM_ENV_IMPORT = /^import \{([^}]+)\} from ['"]esm-env['"];?$/gm;
|
|
2
2
|
const ALIAS = /\s+as\s+/;
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Inlines `esm-env`'s `DEV`, `BROWSER` and `NODE` in a module that imports
|
|
6
|
-
* them. Bun doesn't fold constants imported from another module, so
|
|
7
|
-
* without this every `if (DEV)` branch of Svelte's runtime ships.
|
|
8
|
-
*/
|
|
9
4
|
export function inlineEsmEnv(
|
|
10
5
|
source: string,
|
|
11
6
|
env: { dev: boolean; browser: boolean },
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, join, resolve } from "node:path";
|
|
3
3
|
|
|
4
4
|
import type { BunPlugin, OnLoadArgs } from "bun";
|
|
@@ -64,7 +64,12 @@ type Setup = {
|
|
|
64
64
|
const SVELTE = /\.svelte(\.[jt]s)?$/;
|
|
65
65
|
const SVELTE_CSS = /\.svelte\.css$/;
|
|
66
66
|
const BARE = /^[@a-z]/;
|
|
67
|
-
|
|
67
|
+
// Svelte's runtime, not its compiler. At runtime the hook runs on every
|
|
68
|
+
// module Bun loads, so it stays synchronous: a module an async onLoad
|
|
69
|
+
// returns is async, so is each importer, and import.meta.require can't
|
|
70
|
+
// load the compiler then.
|
|
71
|
+
const SVELTE_RUNTIME =
|
|
72
|
+
/[\\/]node_modules[\\/]svelte[\\/]src[\\/](?!compiler[\\/]).+\.js$/;
|
|
68
73
|
const LIVE_GLOBAL = /\$\.(document|window)\b/g;
|
|
69
74
|
const NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
70
75
|
const RELATIVE = /^\.\.?([\\/]|$)/;
|
|
@@ -296,9 +301,11 @@ export function svelte(options: SvelteBunOptions = {}): BunPlugin {
|
|
|
296
301
|
});
|
|
297
302
|
|
|
298
303
|
if (production) {
|
|
304
|
+
// compat: Bun doesn't fold a constant imported from another
|
|
305
|
+
// module, so Svelte's `if (DEV)` branches would ship.
|
|
299
306
|
const browser = (options.side ?? "client") === "client";
|
|
300
|
-
build.onLoad({ filter: SVELTE_RUNTIME },
|
|
301
|
-
contents: inlineEsmEnv(
|
|
307
|
+
build.onLoad({ filter: SVELTE_RUNTIME }, (args) => ({
|
|
308
|
+
contents: inlineEsmEnv(readFileSync(args.path, "utf8"), {
|
|
302
309
|
dev: false,
|
|
303
310
|
browser,
|
|
304
311
|
}),
|
package/src/register.ts
CHANGED
package/src/resolve.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// undefined where no package is installed.
|
|
5
5
|
export type ExportsCache = Map<string, object | undefined>;
|
|
6
6
|
|
|
7
7
|
function readExports(root: string): object | undefined {
|