@netlify/edge-bundler 1.14.1 → 2.0.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/deno/bundle.ts +2 -2
- package/deno/lib/stage2.ts +6 -21
- package/dist/common/stage2.d.ts +10 -0
- package/dist/{bundle.js → common/stage2.js} +0 -0
- package/dist/{bridge.d.ts → src/bridge.d.ts} +0 -0
- package/dist/{bridge.js → src/bridge.js} +0 -0
- package/dist/{bundle.d.ts → src/bundle.d.ts} +0 -0
- package/dist/{declaration.js → src/bundle.js} +0 -0
- package/dist/{bundle_error.d.ts → src/bundle_error.d.ts} +0 -0
- package/dist/{bundle_error.js → src/bundle_error.js} +0 -0
- package/dist/{bundler.d.ts → src/bundler.d.ts} +1 -1
- package/dist/{bundler.js → src/bundler.js} +0 -0
- package/dist/{declaration.d.ts → src/declaration.d.ts} +0 -0
- package/dist/{edge_function.js → src/declaration.js} +0 -0
- package/dist/{downloader.d.ts → src/downloader.d.ts} +0 -0
- package/dist/{downloader.js → src/downloader.js} +0 -0
- package/dist/{edge_function.d.ts → src/edge_function.d.ts} +0 -0
- package/dist/src/edge_function.js +1 -0
- package/dist/{feature_flags.d.ts → src/feature_flags.d.ts} +0 -0
- package/dist/{feature_flags.js → src/feature_flags.js} +0 -0
- package/dist/{finder.d.ts → src/finder.d.ts} +0 -0
- package/dist/{finder.js → src/finder.js} +0 -0
- package/dist/{formats → src/formats}/eszip.d.ts +0 -0
- package/dist/{formats → src/formats}/eszip.js +1 -1
- package/dist/{formats → src/formats}/javascript.d.ts +0 -0
- package/dist/{formats → src/formats}/javascript.js +0 -0
- package/dist/{home_path.d.ts → src/home_path.d.ts} +0 -0
- package/dist/{home_path.js → src/home_path.js} +0 -0
- package/dist/src/import_map.d.ts +15 -0
- package/dist/src/import_map.js +44 -0
- package/dist/{index.d.ts → src/index.d.ts} +0 -0
- package/dist/{index.js → src/index.js} +0 -0
- package/dist/{logger.d.ts → src/logger.d.ts} +0 -0
- package/dist/{logger.js → src/logger.js} +0 -0
- package/dist/{manifest.d.ts → src/manifest.d.ts} +0 -0
- package/dist/{manifest.js → src/manifest.js} +0 -0
- package/dist/{package_json.d.ts → src/package_json.d.ts} +0 -0
- package/dist/{package_json.js → src/package_json.js} +0 -0
- package/dist/{platform.d.ts → src/platform.d.ts} +0 -0
- package/dist/{platform.js → src/platform.js} +0 -0
- package/dist/{server → src/server}/server.d.ts +0 -0
- package/dist/{server → src/server}/server.js +0 -0
- package/dist/{server → src/server}/util.d.ts +0 -0
- package/dist/{server → src/server}/util.js +0 -0
- package/dist/{types.d.ts → src/types.d.ts} +0 -0
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/{utils → src/utils}/non_nullable.d.ts +0 -0
- package/dist/{utils → src/utils}/non_nullable.js +0 -0
- package/dist/{utils → src/utils}/sha256.d.ts +0 -0
- package/dist/{utils → src/utils}/sha256.js +0 -0
- package/package.json +2 -1
- package/dist/import_map.d.ts +0 -13
- package/dist/import_map.js +0 -30
package/deno/bundle.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writeStage2 } from './lib/stage2.ts'
|
|
2
2
|
|
|
3
3
|
const [payload] = Deno.args
|
|
4
|
-
const { basePath, destPath, functions,
|
|
4
|
+
const { basePath, destPath, functions, importMapURL } = JSON.parse(payload)
|
|
5
5
|
|
|
6
|
-
await writeStage2({ basePath, destPath, functions,
|
|
6
|
+
await writeStage2({ basePath, destPath, functions, importMapURL })
|
package/deno/lib/stage2.ts
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import { build, LoadResponse } from 'https://deno.land/x/eszip@v0.
|
|
1
|
+
import { build, LoadResponse } from 'https://deno.land/x/eszip@v0.28.0/mod.ts'
|
|
2
2
|
|
|
3
3
|
import * as path from 'https://deno.land/std@0.127.0/path/mod.ts'
|
|
4
4
|
|
|
5
|
+
import type { InputFunction, WriteStage2Options } from '../../common/stage2.ts'
|
|
5
6
|
import { PUBLIC_SPECIFIER, STAGE2_SPECIFIER, virtualRoot } from './consts.ts'
|
|
6
7
|
import { inlineModule, loadFromVirtualRoot, loadWithRetry } from './common.ts'
|
|
7
8
|
|
|
8
|
-
interface InputFunction {
|
|
9
|
-
name: string
|
|
10
|
-
path: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface WriteStage2Options {
|
|
14
|
-
basePath: string
|
|
15
|
-
destPath: string
|
|
16
|
-
functions: InputFunction[]
|
|
17
|
-
imports?: Record<string, string>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
9
|
const getFunctionReference = (basePath: string, func: InputFunction, index: number) => {
|
|
21
10
|
const importName = `func${index}`
|
|
22
11
|
const exportLine = `"${func.name}": ${importName}`
|
|
@@ -44,7 +33,7 @@ const getVirtualPath = (basePath: string, filePath: string) => {
|
|
|
44
33
|
return url
|
|
45
34
|
}
|
|
46
35
|
|
|
47
|
-
const stage2Loader = (basePath: string, functions: InputFunction[]
|
|
36
|
+
const stage2Loader = (basePath: string, functions: InputFunction[]) => {
|
|
48
37
|
return async (specifier: string): Promise<LoadResponse | undefined> => {
|
|
49
38
|
if (specifier === STAGE2_SPECIFIER) {
|
|
50
39
|
const stage2Entry = getStage2Entry(basePath, functions)
|
|
@@ -59,10 +48,6 @@ const stage2Loader = (basePath: string, functions: InputFunction[], imports: Rec
|
|
|
59
48
|
}
|
|
60
49
|
}
|
|
61
50
|
|
|
62
|
-
if (imports[specifier] !== undefined) {
|
|
63
|
-
return await loadWithRetry(imports[specifier])
|
|
64
|
-
}
|
|
65
|
-
|
|
66
51
|
if (specifier.startsWith(virtualRoot)) {
|
|
67
52
|
return loadFromVirtualRoot(specifier, virtualRoot, basePath)
|
|
68
53
|
}
|
|
@@ -71,9 +56,9 @@ const stage2Loader = (basePath: string, functions: InputFunction[], imports: Rec
|
|
|
71
56
|
}
|
|
72
57
|
}
|
|
73
58
|
|
|
74
|
-
const writeStage2 = async ({ basePath, destPath, functions,
|
|
75
|
-
const loader = stage2Loader(basePath, functions
|
|
76
|
-
const bytes = await build([STAGE2_SPECIFIER], loader)
|
|
59
|
+
const writeStage2 = async ({ basePath, destPath, functions, importMapURL }: WriteStage2Options) => {
|
|
60
|
+
const loader = stage2Loader(basePath, functions)
|
|
61
|
+
const bytes = await build([STAGE2_SPECIFIER], loader, importMapURL)
|
|
77
62
|
|
|
78
63
|
return await Deno.writeFile(destPath, bytes)
|
|
79
64
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -15,7 +15,7 @@ interface BundleOptions {
|
|
|
15
15
|
onBeforeDownload?: OnBeforeDownloadHook;
|
|
16
16
|
systemLogger?: LogFunction;
|
|
17
17
|
}
|
|
18
|
-
declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { basePath
|
|
18
|
+
declare const bundle: (sourceDirectories: string[], distDirectory: string, declarations?: Declaration[], { basePath, cacheDirectory, debug, distImportMapPath, featureFlags, importMaps, onAfterDownload, onBeforeDownload, systemLogger, }?: BundleOptions) => Promise<{
|
|
19
19
|
functions: EdgeFunction[];
|
|
20
20
|
manifest: import("./manifest.js").Manifest;
|
|
21
21
|
}>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface ImportMapFile {
|
|
2
|
+
baseURL: URL;
|
|
3
|
+
imports: Record<string, string>;
|
|
4
|
+
scopes?: Record<string, Record<string, string>>;
|
|
5
|
+
}
|
|
6
|
+
declare class ImportMap {
|
|
7
|
+
imports: Record<string, URL | null>;
|
|
8
|
+
constructor(files?: ImportMapFile[]);
|
|
9
|
+
static resolve(importMapFile: ImportMapFile): import("@import-maps/resolve/types/src/types").ParsedImportMap;
|
|
10
|
+
getContents(): string;
|
|
11
|
+
toDataURL(): string;
|
|
12
|
+
writeToFile(path: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export { ImportMap };
|
|
15
|
+
export type { ImportMapFile };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
import { parse } from '@import-maps/resolve';
|
|
5
|
+
const INTERNAL_IMPORTS = {
|
|
6
|
+
'netlify:edge': new URL('https://edge.netlify.com/v1/index.ts'),
|
|
7
|
+
};
|
|
8
|
+
class ImportMap {
|
|
9
|
+
constructor(files = []) {
|
|
10
|
+
let imports = {};
|
|
11
|
+
files.forEach((file) => {
|
|
12
|
+
const importMap = ImportMap.resolve(file);
|
|
13
|
+
imports = { ...imports, ...importMap.imports };
|
|
14
|
+
});
|
|
15
|
+
// Internal imports must come last, because we need to guarantee that
|
|
16
|
+
// `netlify:edge` isn't user-defined.
|
|
17
|
+
Object.entries(INTERNAL_IMPORTS).forEach((internalImport) => {
|
|
18
|
+
const [specifier, url] = internalImport;
|
|
19
|
+
imports[specifier] = url;
|
|
20
|
+
});
|
|
21
|
+
this.imports = imports;
|
|
22
|
+
}
|
|
23
|
+
static resolve(importMapFile) {
|
|
24
|
+
const { baseURL, ...importMap } = importMapFile;
|
|
25
|
+
const parsedImportMap = parse(importMap, baseURL);
|
|
26
|
+
return parsedImportMap;
|
|
27
|
+
}
|
|
28
|
+
getContents() {
|
|
29
|
+
const contents = {
|
|
30
|
+
imports: this.imports,
|
|
31
|
+
};
|
|
32
|
+
return JSON.stringify(contents);
|
|
33
|
+
}
|
|
34
|
+
toDataURL() {
|
|
35
|
+
const encodedImportMap = Buffer.from(this.getContents()).toString('base64');
|
|
36
|
+
return `data:application/json;base64,${encodedImportMap}`;
|
|
37
|
+
}
|
|
38
|
+
async writeToFile(path) {
|
|
39
|
+
await fs.mkdir(dirname(path), { recursive: true });
|
|
40
|
+
const contents = this.getContents();
|
|
41
|
+
await fs.writeFile(path, contents);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export { ImportMap };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/edge-bundler",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Intelligently prepare Netlify Edge Functions for deployment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"node": "^12.20.0 || ^14.14.0 || >=16.0.0"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
+
"@import-maps/resolve": "^1.0.1",
|
|
82
83
|
"common-path-prefix": "^3.0.0",
|
|
83
84
|
"del": "^6.0.0",
|
|
84
85
|
"env-paths": "^3.0.0",
|
package/dist/import_map.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
interface ImportMapFile {
|
|
2
|
-
imports: Record<string, string>;
|
|
3
|
-
scopes?: Record<string, string>;
|
|
4
|
-
}
|
|
5
|
-
declare class ImportMap {
|
|
6
|
-
imports: Record<string, string>;
|
|
7
|
-
constructor(input?: ImportMapFile[]);
|
|
8
|
-
getContents(): string;
|
|
9
|
-
toDataURL(): string;
|
|
10
|
-
writeToFile(path: string): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export { ImportMap };
|
|
13
|
-
export type { ImportMapFile };
|
package/dist/import_map.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
import { promises as fs } from 'fs';
|
|
3
|
-
import { dirname } from 'path';
|
|
4
|
-
const INTERNAL_IMPORTS = {
|
|
5
|
-
'netlify:edge': 'https://edge.netlify.com/v1/index.ts',
|
|
6
|
-
};
|
|
7
|
-
class ImportMap {
|
|
8
|
-
constructor(input = []) {
|
|
9
|
-
const inputImports = input.reduce((acc, { imports }) => ({ ...acc, ...imports }), {});
|
|
10
|
-
// `INTERNAL_IMPORTS` must come last,
|
|
11
|
-
// because we need to guarantee `netlify:edge` isn't user-defined.
|
|
12
|
-
this.imports = { ...inputImports, ...INTERNAL_IMPORTS };
|
|
13
|
-
}
|
|
14
|
-
getContents() {
|
|
15
|
-
const contents = {
|
|
16
|
-
imports: this.imports,
|
|
17
|
-
};
|
|
18
|
-
return JSON.stringify(contents);
|
|
19
|
-
}
|
|
20
|
-
toDataURL() {
|
|
21
|
-
const encodedImportMap = Buffer.from(this.getContents()).toString('base64');
|
|
22
|
-
return `data:application/json;base64,${encodedImportMap}`;
|
|
23
|
-
}
|
|
24
|
-
async writeToFile(path) {
|
|
25
|
-
await fs.mkdir(dirname(path), { recursive: true });
|
|
26
|
-
const contents = this.getContents();
|
|
27
|
-
await fs.writeFile(path, contents);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export { ImportMap };
|