@yaks/esbuild 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +450 -2
- package/_dist/bundle.d.ts +6 -0
- package/_dist/bundle.d.ts.map +1 -0
- package/_dist/compile.d.ts +72 -0
- package/_dist/compile.d.ts.map +1 -0
- package/_dist/dependencies.d.ts +15 -0
- package/_dist/dependencies.d.ts.map +1 -0
- package/_dist/file.d.ts +185 -0
- package/_dist/file.d.ts.map +1 -0
- package/_dist/graph.d.ts +104 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/home.d.ts +15 -0
- package/_dist/home.d.ts.map +1 -0
- package/_dist/link.d.ts +192 -0
- package/_dist/link.d.ts.map +1 -0
- package/_dist/lock.d.ts +30 -0
- package/_dist/lock.d.ts.map +1 -0
- package/_dist/mod.d.ts +6 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/pack.d.ts +42 -0
- package/_dist/pack.d.ts.map +1 -0
- package/_dist/package.d.ts +11 -0
- package/_dist/package.d.ts.map +1 -0
- package/_dist/plan.d.ts +135 -0
- package/_dist/plan.d.ts.map +1 -0
- package/_dist/platform.d.ts +27 -0
- package/_dist/platform.d.ts.map +1 -0
- package/_dist/resolve.d.ts +42 -0
- package/_dist/resolve.d.ts.map +1 -0
- package/_dist/shelf.d.ts +11 -0
- package/_dist/shelf.d.ts.map +1 -0
- package/_dist/strip.d.ts +51 -0
- package/_dist/strip.d.ts.map +1 -0
- package/_dist/timing.d.ts +6 -0
- package/_dist/timing.d.ts.map +1 -0
- package/_dist/unpack.d.ts +14 -0
- package/_dist/unpack.d.ts.map +1 -0
- package/analysis.js +72 -0
- package/analysis.js.map +1 -0
- package/analysis.ts +82 -0
- package/bundle.js +320 -0
- package/bundle.js.map +1 -0
- package/bundle.ts +415 -0
- package/common.js +129 -0
- package/common.js.map +1 -0
- package/common.ts +138 -0
- package/compile.js +500 -0
- package/compile.js.map +1 -0
- package/compile.ts +622 -0
- package/container.js +142 -0
- package/container.js.map +1 -0
- package/container.ts +183 -0
- package/deno.json +1 -0
- package/dependencies.js +31 -0
- package/dependencies.js.map +1 -0
- package/dependencies.ts +40 -0
- package/file.js +303 -0
- package/file.js.map +1 -0
- package/file.ts +443 -0
- package/forward.ts +49 -0
- package/graph.js +297 -0
- package/graph.js.map +1 -0
- package/graph.ts +360 -0
- package/home.js +40 -0
- package/home.js.map +1 -0
- package/home.ts +52 -0
- package/link.js +455 -0
- package/link.js.map +1 -0
- package/link.ts +596 -0
- package/lock.js +129 -0
- package/lock.js.map +1 -0
- package/lock.ts +161 -0
- package/mod.js +14 -0
- package/mod.js.map +1 -0
- package/mod.ts +43 -0
- package/npm.js +362 -0
- package/npm.js.map +1 -0
- package/npm.ts +429 -0
- package/pack.js +188 -0
- package/pack.js.map +1 -0
- package/pack.ts +225 -0
- package/package.js +199 -0
- package/package.js.map +1 -0
- package/package.json +60 -4
- package/package.ts +255 -0
- package/plan.js +273 -0
- package/plan.js.map +1 -0
- package/plan.ts +395 -0
- package/platform.js +160 -0
- package/platform.js.map +1 -0
- package/platform.ts +238 -0
- package/resolve.js +86 -0
- package/resolve.js.map +1 -0
- package/resolve.ts +144 -0
- package/said.js +44 -0
- package/said.js.map +1 -0
- package/said.ts +61 -0
- package/serve.ts +37 -0
- package/sha256.js +7 -0
- package/sha256.js.map +1 -0
- package/sha256.ts +10 -0
- package/shared.js +646 -0
- package/shared.js.map +1 -0
- package/shared.ts +813 -0
- package/shelf.js +73 -0
- package/shelf.js.map +1 -0
- package/shelf.ts +110 -0
- package/strip.js +114 -0
- package/strip.js.map +1 -0
- package/strip.ts +117 -0
- package/tar.js +87 -0
- package/tar.js.map +1 -0
- package/tar.ts +99 -0
- package/timing.js +37 -0
- package/timing.js.map +1 -0
- package/timing.ts +71 -0
- package/unpack.js +40 -0
- package/unpack.js.map +1 -0
- package/unpack.ts +60 -0
- package/used.js +91 -0
- package/used.js.map +1 -0
- package/used.ts +116 -0
package/pack.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// A page's modules packed into a few (D-499's fallback, T-5738, T-5647). A
|
|
2
|
+
// page of hashed modules goes live at once and loads every module it reaches
|
|
3
|
+
// beside its first, but hundreds of modules at once wait at the host's door,
|
|
4
|
+
// and a package's entries cannot shed what the page never uses; one pack is a
|
|
5
|
+
// few requests, tree-shaken. A host packs after the release is live, never
|
|
6
|
+
// before, and the page switches to the pack once it is kept.
|
|
7
|
+
//
|
|
8
|
+
// A pack is what esbuild bundles from the page's roots over the modules as
|
|
9
|
+
// compiled (./file.ts), each already JavaScript: the app's own, and the
|
|
10
|
+
// package modules its import map names (`imports`, a bare specifier to an
|
|
11
|
+
// address, and `packages`, each module's text by its address). A bare
|
|
12
|
+
// specifier the map does not name, or names a module not given, stays bare
|
|
13
|
+
// for the page's map. Every file a pack writes is served at the app's root,
|
|
14
|
+
// so what an app's module imports that the pack does not hold
|
|
15
|
+
// (`./api/client.js`, a JSON file) is written by its path from there, and a
|
|
16
|
+
// module's `import.meta.url` becomes its own address, as when it loaded
|
|
17
|
+
// alone. A module that computes a path it imports from, or reads
|
|
18
|
+
// `import.meta` beyond its URL, is not packed: its page keeps its modules.
|
|
19
|
+
import { parse } from 'es-module-lexer/js'
|
|
20
|
+
import { bundle, Stopped } from './bundle.js'
|
|
21
|
+
import { found } from './graph.js'
|
|
22
|
+
import { moved, urlOf } from './platform.js'
|
|
23
|
+
import { said } from './said.js'
|
|
24
|
+
|
|
25
|
+
/** What a host posts to have a page's modules packed: its roots, each a
|
|
26
|
+
* script's path from the app's root, and every module of the app by path,
|
|
27
|
+
* compiled. */
|
|
28
|
+
export type PackJob = {
|
|
29
|
+
pack: {
|
|
30
|
+
roots: string[]
|
|
31
|
+
modules: Record<string, string>
|
|
32
|
+
packages?: Record<string, string>
|
|
33
|
+
imports?: Record<string, string>
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A pack: the file each root became, each file's text, and what each
|
|
38
|
+
* imports statically, another of its files by `./<file>` or a bare
|
|
39
|
+
* specifier, which a page preloads. */
|
|
40
|
+
export type Packed = {
|
|
41
|
+
entries: Record<string, string>
|
|
42
|
+
files: Record<string, string>
|
|
43
|
+
links: Record<string, string[]>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Modules a pack would not load as they load alone. */
|
|
47
|
+
export class Unpackable extends Error {
|
|
48
|
+
override name = 'Unpackable'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let RELATIVE = /^\.\.?\//
|
|
52
|
+
let META_URL = /^\s*\.\s*url\b/
|
|
53
|
+
// An import() of a URL it makes whole, which means the same from a pack:
|
|
54
|
+
// against the page (`document.baseURI`), or the module's own address, which
|
|
55
|
+
// `import.meta.url` still is. Any other computed specifier may be a path
|
|
56
|
+
// from the module, which a pack moves.
|
|
57
|
+
let ADDRESSED = /^\s*new\s+URL\s*\(/
|
|
58
|
+
|
|
59
|
+
// Where `spec`, imported by the module at `path`, is: its path from the
|
|
60
|
+
// app's root as written in a URL, and decoded, as a module is keyed.
|
|
61
|
+
let at = (path: string, spec: string) => {
|
|
62
|
+
let url = new URL(spec, `https://app.invalid/${path}`)
|
|
63
|
+
return {
|
|
64
|
+
written: url.pathname.slice(1) + url.search,
|
|
65
|
+
path: decodeURIComponent(url.pathname.slice(1)),
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Where a package module is read in a pack, beside the app's paths: by its
|
|
70
|
+
// file under `__m/`, so its imports of its package's other modules, written
|
|
71
|
+
// `./<file>`, resolve beside it.
|
|
72
|
+
let PACKAGE = '__m/'
|
|
73
|
+
let packageKey = (address: string) =>
|
|
74
|
+
PACKAGE + address.slice(address.lastIndexOf('/') + 1)
|
|
75
|
+
|
|
76
|
+
// `spec` from a package module's address, which is a whole URL or, on the
|
|
77
|
+
// page's own origin, a path from its root.
|
|
78
|
+
let beside = (address: string, spec: string) => {
|
|
79
|
+
let url = new URL(spec, new URL(address, 'https://origin.invalid'))
|
|
80
|
+
return url.origin == 'https://origin.invalid'
|
|
81
|
+
? url.pathname + url.search
|
|
82
|
+
: url.href
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Every module the roots reach, by import or by `import()`, each with its
|
|
86
|
+
// `import.meta.url` read as its own address: an app's module by its path,
|
|
87
|
+
// and a package module by the address the map names.
|
|
88
|
+
let reached = (
|
|
89
|
+
roots: string[],
|
|
90
|
+
modules: Record<string, string>,
|
|
91
|
+
packages: Record<string, string>,
|
|
92
|
+
imports: Record<string, string>,
|
|
93
|
+
) => {
|
|
94
|
+
let addresses = new Map(
|
|
95
|
+
Object.keys(packages).map((address) => [packageKey(address), address]),
|
|
96
|
+
)
|
|
97
|
+
let textOf = (key: string) =>
|
|
98
|
+
addresses.has(key)
|
|
99
|
+
? packages[addresses.get(key)!]
|
|
100
|
+
: Object.hasOwn(modules, key) && !key.startsWith(PACKAGE)
|
|
101
|
+
? modules[key]
|
|
102
|
+
: null
|
|
103
|
+
let seen = new Map<string, string>()
|
|
104
|
+
let next = [...roots]
|
|
105
|
+
while (next.length) {
|
|
106
|
+
let path = next.pop()!
|
|
107
|
+
let js = seen.has(path) ? null : textOf(path)
|
|
108
|
+
if (js == null) continue
|
|
109
|
+
let lexed
|
|
110
|
+
try {
|
|
111
|
+
lexed = parse(js)[0]
|
|
112
|
+
} catch {
|
|
113
|
+
throw new Unpackable(`${path} does not parse`)
|
|
114
|
+
}
|
|
115
|
+
for (let { n: spec, d, s, e } of lexed) {
|
|
116
|
+
if (d == -2) {
|
|
117
|
+
if (!META_URL.test(js.slice(e))) {
|
|
118
|
+
throw new Unpackable(`${path} reads import.meta beyond its url`)
|
|
119
|
+
}
|
|
120
|
+
} else if (spec == null) {
|
|
121
|
+
// A package's modules import bare or whole URLs, never a path from
|
|
122
|
+
// their own (@yaks/esbuild/package), so what one computes means the
|
|
123
|
+
// same from a pack.
|
|
124
|
+
if (!addresses.has(path) && !ADDRESSED.test(js.slice(s, e))) {
|
|
125
|
+
throw new Unpackable(`${path} imports a module it computes`)
|
|
126
|
+
}
|
|
127
|
+
} else if (RELATIVE.test(spec)) {
|
|
128
|
+
let to = at(path, spec).path
|
|
129
|
+
next.push(found(to, (p) => textOf(p) != null) ?? to)
|
|
130
|
+
} else if (Object.hasOwn(imports, spec)) {
|
|
131
|
+
next.push(packageKey(imports[spec]))
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let address = addresses.get(path)
|
|
135
|
+
seen.set(
|
|
136
|
+
path,
|
|
137
|
+
moved(js, () => urlOf(address ?? `./${encodeURI(path)}`)),
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
return { texts: seen, addresses }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// What each file imports statically: another of the pack's files, or a bare
|
|
144
|
+
// specifier.
|
|
145
|
+
let linksOf = (files: Record<string, string>) =>
|
|
146
|
+
Object.fromEntries(
|
|
147
|
+
Object.entries(files).map(([file, js]) => {
|
|
148
|
+
let out = new Set<string>()
|
|
149
|
+
for (let { n: spec, d } of parse(js)[0]) {
|
|
150
|
+
if (spec == null || d != -1) continue
|
|
151
|
+
if (RELATIVE.test(spec)) {
|
|
152
|
+
let to = spec.replace(/^\.\//, '')
|
|
153
|
+
if (Object.hasOwn(files, to)) out.add(`./${to}`)
|
|
154
|
+
} else if (!spec.startsWith('/') && !spec.includes(':')) out.add(spec)
|
|
155
|
+
}
|
|
156
|
+
return [file, [...out]]
|
|
157
|
+
}),
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
/** The modules `roots` reach, packed: one file a root, and chunks the roots
|
|
161
|
+
* share. Throws {@link Unpackable} for modules that would not load packed
|
|
162
|
+
* as they load alone or that esbuild refuses, and for a root no module is;
|
|
163
|
+
* `Stopped` when esbuild's process ended under it.
|
|
164
|
+
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { assertEquals } from '@std/assert'
|
|
167
|
+
* let { entries, files, links } = await packModules({
|
|
168
|
+
* roots: ['main.ts'],
|
|
169
|
+
* modules: {
|
|
170
|
+
* 'main.ts': "import { n } from './lib/n.ts'\n" +
|
|
171
|
+
* "import { h } from 'preact'\nexport let x = h(n)",
|
|
172
|
+
* 'lib/n.ts': 'export let n = new URL("./a.png", import.meta.url).href',
|
|
173
|
+
* },
|
|
174
|
+
* })
|
|
175
|
+
* let main = files[entries['main.ts']]
|
|
176
|
+
* assertEquals(/from\s*['"]preact['"]/.test(main), true)
|
|
177
|
+
* assertEquals(main.includes('"./lib/n.ts"'), true)
|
|
178
|
+
* assertEquals(links[entries['main.ts']], ['preact'])
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export let packModules = async (
|
|
182
|
+
{ roots, modules, packages = {}, imports = {} }: PackJob['pack'],
|
|
183
|
+
): Promise<Packed> => {
|
|
184
|
+
for (let root of roots) {
|
|
185
|
+
if (!Object.hasOwn(modules, root)) {
|
|
186
|
+
throw new Unpackable(`${root} is no module of the app`)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
let { texts, addresses } = reached(roots, modules, packages, imports)
|
|
190
|
+
let names = Object.fromEntries(roots.map((root, i) => [`pack-${i}`, root]))
|
|
191
|
+
// What esbuild refuses of the app's code it refuses every time: the
|
|
192
|
+
// modules are not packed, and esbuild's lines say why.
|
|
193
|
+
let built = await bundle(
|
|
194
|
+
{ read: (path) => texts.get(path) ?? null },
|
|
195
|
+
names,
|
|
196
|
+
{
|
|
197
|
+
loader: 'js',
|
|
198
|
+
// As a page's bundle was built (./compile.ts).
|
|
199
|
+
minify: true,
|
|
200
|
+
define: { 'process.env.NODE_ENV': '"production"' },
|
|
201
|
+
alias: (spec) => {
|
|
202
|
+
let key = !RELATIVE.test(spec) && Object.hasOwn(imports, spec) &&
|
|
203
|
+
packageKey(imports[spec])
|
|
204
|
+
return key && texts.has(key) ? key : undefined
|
|
205
|
+
},
|
|
206
|
+
external: (spec, importer) => {
|
|
207
|
+
if (!RELATIVE.test(spec)) return spec
|
|
208
|
+
let to = at(importer, spec)
|
|
209
|
+
if (found(to.path, (p) => texts.has(p))) return undefined
|
|
210
|
+
// A package's file the pack does not hold, at its own address.
|
|
211
|
+
let address = addresses.get(importer)
|
|
212
|
+
return address ? beside(address, spec) : `./${to.written}`
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
).catch((e) => {
|
|
216
|
+
throw e instanceof Stopped ? e : new Unpackable(said(e).join('\n'))
|
|
217
|
+
})
|
|
218
|
+
return {
|
|
219
|
+
entries: Object.fromEntries(
|
|
220
|
+
Object.entries(names).map(([name, root]) => [root, `${name}.js`]),
|
|
221
|
+
),
|
|
222
|
+
files: built.files,
|
|
223
|
+
links: linksOf(built.files),
|
|
224
|
+
}
|
|
225
|
+
}
|
package/package.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// A package compiled once for the whole platform (D-499): an npm package at
|
|
2
|
+
// an exact version, or a @yaks package at a published one, built into one
|
|
3
|
+
// module per export entry, with the files entries share split into chunks so
|
|
4
|
+
// each module the package holds has one instance whichever entries a page
|
|
5
|
+
// imports. Every import of another package, and of this one by its own name,
|
|
6
|
+
// stays bare as written: the import map of the page that loads it says where
|
|
7
|
+
// that is. So a package's bytes never depend on the app that uses it, or on
|
|
8
|
+
// the versions of what it imports, and one compile serves every app.
|
|
9
|
+
//
|
|
10
|
+
// Each emitted module is named for the package's key and its place in the
|
|
11
|
+
// build, `compiledName`'s kind of name: a key names one package version, built
|
|
12
|
+
// by one compiler, so a name is written once and never changes, and the
|
|
13
|
+
// chunks an entry imports are named before any of them is written.
|
|
14
|
+
import { parse } from "es-module-lexer/js";
|
|
15
|
+
import { initSync, parse as cjs } from "cjs-module-lexer";
|
|
16
|
+
import { posix } from 'node:path';
|
|
17
|
+
import { bundle, packaged, typedName } from "./bundle.js";
|
|
18
|
+
import { COMPILER, Unexported } from "./file.js";
|
|
19
|
+
import { rewritten } from "./link.js";
|
|
20
|
+
import { packageOf } from "./graph.js";
|
|
21
|
+
let hex = (bytes)=>Array.from(new Uint8Array(bytes), (b)=>b.toString(16).padStart(2, '0')).join('');
|
|
22
|
+
let sha256 = async (text)=>hex(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text)));
|
|
23
|
+
/** Each concrete browser export of an installed package, by specifier, as
|
|
24
|
+
* the file it resolves to. Every one is an entry of the same splitting build,
|
|
25
|
+
* which keeps one instance of each module whichever subpaths a page imports. */ export let exportsOf = (files, name)=>{
|
|
26
|
+
let pkg = JSON.parse(files.read(`node_modules/${name}/package.json`));
|
|
27
|
+
let keys = typeof pkg.exports == 'object' && pkg.exports != null && Object.keys(pkg.exports).some((key)=>key.startsWith('.')) ? Object.keys(pkg.exports) : [
|
|
28
|
+
'.'
|
|
29
|
+
];
|
|
30
|
+
// Preact also exports SSR adapters whose optional renderer peer belongs to
|
|
31
|
+
// server consumers. They cannot be entries of a browser build.
|
|
32
|
+
if (name == 'preact') {
|
|
33
|
+
keys = keys.filter((key)=>!key.startsWith('./compat/server'));
|
|
34
|
+
}
|
|
35
|
+
if (name == 'react-dom') {
|
|
36
|
+
keys = keys.filter((key)=>!/^\.\/(?:server|static)\./.test(key));
|
|
37
|
+
}
|
|
38
|
+
let out = {};
|
|
39
|
+
for (let key of keys.sort()){
|
|
40
|
+
// A pattern export names no one file; a page imports what it matches.
|
|
41
|
+
if (key.includes('*')) continue;
|
|
42
|
+
let spec = key == '.' ? name : name + key.slice(1);
|
|
43
|
+
let path = packaged(files, spec);
|
|
44
|
+
if (path && !path.endsWith('.json')) out[spec] = path;
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
};
|
|
48
|
+
/** An ES module standing for a CommonJS file: its `module.exports` as the
|
|
49
|
+
* default, and each name CommonJS assigns, including those it forwards from
|
|
50
|
+
* the files it re-exports, by name, so `import { useState } from 'react'`
|
|
51
|
+
* links. */ export let commonJS = (files, path)=>{
|
|
52
|
+
initSync();
|
|
53
|
+
let names = new Set();
|
|
54
|
+
let seen = new Set();
|
|
55
|
+
let visit = (file)=>{
|
|
56
|
+
if (seen.has(file)) return;
|
|
57
|
+
seen.add(file);
|
|
58
|
+
let source = files.read(file);
|
|
59
|
+
if (source == null) return;
|
|
60
|
+
let { exports, reexports } = cjs(source);
|
|
61
|
+
for (let name of exports){
|
|
62
|
+
if (name != 'default' && name != '__esModule') names.add(name);
|
|
63
|
+
}
|
|
64
|
+
for (let next of reexports){
|
|
65
|
+
if (next.startsWith('.')) visit(posix.join(posix.dirname(file), next));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
visit(path);
|
|
69
|
+
return [
|
|
70
|
+
`import value from ${JSON.stringify('/' + path)}`,
|
|
71
|
+
'export default value',
|
|
72
|
+
...[
|
|
73
|
+
...names
|
|
74
|
+
].sort().map((name, i)=>`let n${i} = value[${JSON.stringify(name)}]; export { n${i} as ${JSON.stringify(name)} }`)
|
|
75
|
+
].join('\n');
|
|
76
|
+
};
|
|
77
|
+
// Whether a package file is CommonJS: `.cjs`, or JavaScript with no import
|
|
78
|
+
// or export in it that Node does not type as an ES module (a UMD script
|
|
79
|
+
// under `"type": "module"` is a module that exports nothing, as Node loads
|
|
80
|
+
// it). TypeScript is a module.
|
|
81
|
+
let isCommonJS = (files, path)=>{
|
|
82
|
+
if (path.endsWith('.cjs')) return true;
|
|
83
|
+
if (!path.endsWith('.js') || typedName(files, path) != path) return false;
|
|
84
|
+
try {
|
|
85
|
+
return !parse(files.read(path) ?? '')[3];
|
|
86
|
+
} catch {
|
|
87
|
+
return false // esbuild names the syntax error
|
|
88
|
+
;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
let SCRIPT = /\.[mc]?[jt]sx?$/;
|
|
92
|
+
// CommonJS's `require` of another package, as a module of this build: the
|
|
93
|
+
// package imported bare, as an ES module would import it, which esbuild hands
|
|
94
|
+
// `require` as an object. Its default is what a CommonJS package compiles to
|
|
95
|
+
// (`commonJS`), its `module.exports`.
|
|
96
|
+
let required = (spec)=>[
|
|
97
|
+
`import * as m from ${JSON.stringify(spec)}`,
|
|
98
|
+
`export * from ${JSON.stringify(spec)}`,
|
|
99
|
+
'export default m.default'
|
|
100
|
+
].join('\n');
|
|
101
|
+
let REQUIRED = '__required/';
|
|
102
|
+
let ENTRY = '__entry/';
|
|
103
|
+
let production = {
|
|
104
|
+
minify: true,
|
|
105
|
+
define: {
|
|
106
|
+
'process.env.NODE_ENV': '"production"'
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/** Compile the package `name`, installed in `files` under `node_modules/`,
|
|
110
|
+
* as `key` names it (`preact@10.26.0`): its export entries, minified, for a
|
|
111
|
+
* browser. `moved` is how a module that reads `import.meta.url` finds the
|
|
112
|
+
* package's other files (./bundle.ts). With `subpath`, a specifier a pattern
|
|
113
|
+
* export matches (`three/addons/controls/OrbitControls.js`), the build is of
|
|
114
|
+
* that alone: the files it reaches are in it, and its imports of the
|
|
115
|
+
* package's concrete exports stay bare. Throws esbuild's failure. */ export let packageModules = async (files, name, key, { moved, subpath } = {})=>{
|
|
116
|
+
// A stylesheet entry is a file a page links, not a module.
|
|
117
|
+
let concrete = Object.fromEntries(Object.entries(exportsOf(files, name)).filter(([, p])=>SCRIPT.test(p)));
|
|
118
|
+
let entries = concrete;
|
|
119
|
+
if (subpath) {
|
|
120
|
+
let path = packaged(files, subpath);
|
|
121
|
+
if (!path || !SCRIPT.test(path)) {
|
|
122
|
+
throw new Unexported(`${subpath} names no module of ${name}`);
|
|
123
|
+
}
|
|
124
|
+
entries = {
|
|
125
|
+
[subpath]: path
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
let specs = Object.keys(entries).sort();
|
|
129
|
+
let written = {};
|
|
130
|
+
let points = {};
|
|
131
|
+
specs.forEach((spec, i)=>{
|
|
132
|
+
let path = entries[spec];
|
|
133
|
+
if (isCommonJS(files, path)) {
|
|
134
|
+
path = `${ENTRY}${i}.js`;
|
|
135
|
+
written[path] = commonJS(files, entries[spec]);
|
|
136
|
+
}
|
|
137
|
+
points[`entry-${i}`] = path;
|
|
138
|
+
});
|
|
139
|
+
let source = {
|
|
140
|
+
read: (path)=>written[path] ?? (path.startsWith(REQUIRED) ? required(path.slice(REQUIRED.length, -'.js'.length)) : files.read(path))
|
|
141
|
+
};
|
|
142
|
+
let built = await bundle(source, points, {
|
|
143
|
+
...production,
|
|
144
|
+
moved,
|
|
145
|
+
alias: (spec, _, kind)=>kind == 'require-call' && packageOf(spec) ? `${REQUIRED}${spec}.js` : undefined,
|
|
146
|
+
// Another package stays bare; so does this one by name, unless what it
|
|
147
|
+
// names is no entry, which only this build can reach.
|
|
148
|
+
external: (spec)=>{
|
|
149
|
+
let of = packageOf(spec);
|
|
150
|
+
if (!of) return;
|
|
151
|
+
if (of != name || spec in concrete || !packaged(files, spec)) return spec;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
let names = Object.fromEntries(await Promise.all(Object.keys(built.files).map(async (file)=>{
|
|
155
|
+
let ext = file.slice(file.lastIndexOf('.'));
|
|
156
|
+
return [
|
|
157
|
+
file,
|
|
158
|
+
await sha256(`${COMPILER}\0${key}\0${file}`) + ext
|
|
159
|
+
];
|
|
160
|
+
})));
|
|
161
|
+
let modules = {};
|
|
162
|
+
let imports = new Set();
|
|
163
|
+
let links = {};
|
|
164
|
+
for (let [file, code] of Object.entries(built.files)){
|
|
165
|
+
if (!file.endsWith('.js')) {
|
|
166
|
+
modules[names[file]] = code;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
modules[names[file]] = linked(code, names);
|
|
170
|
+
let statics = new Set();
|
|
171
|
+
for (let { n, d } of parse(code)[0]){
|
|
172
|
+
if (!n) continue;
|
|
173
|
+
let bare = packageOf(n);
|
|
174
|
+
if (bare) imports.add(n);
|
|
175
|
+
// -1 is a static import; a dynamic one loads only when it runs.
|
|
176
|
+
if (d != -1) continue;
|
|
177
|
+
let to = bare ? n : n.startsWith('./') && names[n.slice(2)] ? `./${names[n.slice(2)]}` : undefined;
|
|
178
|
+
if (to) statics.add(to);
|
|
179
|
+
}
|
|
180
|
+
links[names[file]] = [
|
|
181
|
+
...statics
|
|
182
|
+
].sort();
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
entries: Object.fromEntries(specs.map((spec, i)=>[
|
|
186
|
+
spec,
|
|
187
|
+
names[`entry-${i}.js`]
|
|
188
|
+
])),
|
|
189
|
+
modules,
|
|
190
|
+
imports: [
|
|
191
|
+
...imports
|
|
192
|
+
].sort(),
|
|
193
|
+
links
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
// A module's imports of the build's other files, by the names they are kept
|
|
197
|
+
// under.
|
|
198
|
+
let linked = (code, names)=>rewritten(code, (n)=>n.startsWith('./') && names[n.slice(2)] ? `./${names[n.slice(2)]}` : undefined);
|
|
199
|
+
//# sourceMappingURL=package.js.map
|
package/package.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","sources":["./package.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,qEAAqE;AACrE,EAAE;AACF,0EAA0E;AAC1E,+EAA+E;AAC/E,wEAAwE;AACxE,mEAAmE;AACnE,SAAS,KAAK,6BAAsC;AACpD,SAAS,QAAQ,EAAE,SAAS,GAAG,2BAAoC;AACnE,SAAS,KAAK,QAAQ,YAAW;AACjC,SACE,MAAM,EAEN,QAAQ,EAER,SAAS,sBACS;AACpB,SAAS,QAAQ,EAAE,UAAU,oBAAmB;AAChD,SAAS,SAAS,oBAAmB;AACrC,SAAS,SAAS,qBAAoB;AActC,IAAI,MAAM,CAAC,QACT,MAAM,IAAI,CAAC,IAAI,WAAW,QAAQ,CAAC,IAAM,EAAE,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,MACjE,IAAI,CAAC;AACV,IAAI,SAAS,OAAO,O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AK,CAAC,KAAK,CAAC,GAAG;SAAI;KAAQ,CAAC,IAAI;EACxC;EACA,OAAO;IACL,SAAS,OAAO,WAAW,CACzB,MAAM,GAAG,CAAC,CAAC,MAAM,IAAM;QAAC;QAAM,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC;OAAC;IAEvD;IACA,SAAS;SAAI;KAAQ,CAAC,IAAI;IAC1B;EACF;AACF,EAAC;AAED,4EAA4E;AAC5E,SAAS;AACT,IAAI,SAAS,CAAC,MAAc,QAC1B,UACE,MACA,CAAC,IACC,EAAE,UAAU,CAAC,SAAS,KAAK,CAAC,EAAE,KAAK,CAAC,GAAG,GACnC,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,GAAG,EAAE,GACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaks/esbuild",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.36",
|
|
4
|
+
"homepage": "https://jsr.io/@yaks/esbuild",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./_dist/mod.d.ts",
|
|
9
|
+
"default": "./mod.js"
|
|
10
|
+
},
|
|
11
|
+
"./plan": {
|
|
12
|
+
"types": "./_dist/plan.d.ts",
|
|
13
|
+
"default": "./plan.js"
|
|
14
|
+
},
|
|
15
|
+
"./compile": {
|
|
16
|
+
"types": "./_dist/compile.d.ts",
|
|
17
|
+
"default": "./compile.js"
|
|
18
|
+
},
|
|
19
|
+
"./unpack": {
|
|
20
|
+
"types": "./_dist/unpack.d.ts",
|
|
21
|
+
"default": "./unpack.js"
|
|
22
|
+
},
|
|
23
|
+
"./strip": {
|
|
24
|
+
"types": "./_dist/strip.d.ts",
|
|
25
|
+
"default": "./strip.js"
|
|
26
|
+
},
|
|
27
|
+
"./file": {
|
|
28
|
+
"types": "./_dist/file.d.ts",
|
|
29
|
+
"default": "./file.js"
|
|
30
|
+
},
|
|
31
|
+
"./link": {
|
|
32
|
+
"types": "./_dist/link.d.ts",
|
|
33
|
+
"default": "./link.js"
|
|
34
|
+
},
|
|
35
|
+
"./pack": {
|
|
36
|
+
"types": "./_dist/pack.d.ts",
|
|
37
|
+
"default": "./pack.js"
|
|
38
|
+
},
|
|
39
|
+
"./resolve": {
|
|
40
|
+
"types": "./_dist/resolve.d.ts",
|
|
41
|
+
"default": "./resolve.js"
|
|
42
|
+
},
|
|
43
|
+
"./dependencies": {
|
|
44
|
+
"types": "./_dist/dependencies.d.ts",
|
|
45
|
+
"default": "./dependencies.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"license": "Apache-2.0",
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@noble/hashes": "2.4.0",
|
|
51
|
+
"@types/semver": "^7.8.0",
|
|
52
|
+
"cjs-module-lexer": "2.3.0",
|
|
53
|
+
"es-module-lexer": "2.3.2",
|
|
54
|
+
"esbuild": "0.28.1",
|
|
55
|
+
"fflate": "0.8.3",
|
|
56
|
+
"resolve.exports": "2.0.3",
|
|
57
|
+
"semver": "7.8.5",
|
|
58
|
+
"sucrase": "3.35.1"
|
|
59
|
+
},
|
|
60
|
+
"description": "Compiles an app's TypeScript and npm imports: the module graph of its files, what a deploy must compile, and the compile itself with native esbuild, which yaks.app runs in a container.",
|
|
61
|
+
"repository": "https://github.com/yak-sh/yak.git"
|
|
62
|
+
}
|