@fastly/compute-js-static-publish 2.2.2 → 2.3.0-alpha.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/build/assets.d.ts +8 -0
- package/build/assets.d.ts.map +1 -0
- package/build/assets.js +24 -0
- package/build/build-static.d.ts +3 -0
- package/build/build-static.d.ts.map +1 -0
- package/build/build-static.js +0 -3
- package/build/cli.d.ts +3 -0
- package/build/cli.d.ts.map +1 -0
- package/build/cli.js +77 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +2 -77
- package/build/init-app.d.ts +3 -0
- package/build/init-app.d.ts.map +1 -0
- package/build/presets/implementations/create-react-app.d.ts +16 -0
- package/build/presets/implementations/create-react-app.d.ts.map +1 -0
- package/build/presets/implementations/docusaurus.d.ts +11 -0
- package/build/presets/implementations/docusaurus.d.ts.map +1 -0
- package/build/presets/implementations/gatsby.d.ts +11 -0
- package/build/presets/implementations/gatsby.d.ts.map +1 -0
- package/build/presets/implementations/next.d.ts +11 -0
- package/build/presets/implementations/next.d.ts.map +1 -0
- package/build/presets/implementations/sveltekit.d.ts +11 -0
- package/build/presets/implementations/sveltekit.d.ts.map +1 -0
- package/build/presets/implementations/vite.d.ts +11 -0
- package/build/presets/implementations/vite.d.ts.map +1 -0
- package/build/presets/index.d.ts +3 -0
- package/build/presets/index.d.ts.map +1 -0
- package/build/presets/preset-base.d.ts +18 -0
- package/build/presets/preset-base.d.ts.map +1 -0
- package/build/static-assets.d.ts +8 -0
- package/build/static-assets.d.ts.map +1 -0
- package/build/static-assets.js +24 -0
- package/build/types.d.ts +26 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +1 -0
- package/package.json +13 -4
- package/.idea/compute-js-static-publish.iml +0 -12
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/src/build-static.ts +0 -245
- package/src/content-types.ts +0 -7
- package/src/index.ts +0 -89
- package/src/init-app.ts +0 -331
- package/src/presets/implementations/create-react-app.ts +0 -34
- package/src/presets/implementations/docusaurus.ts +0 -13
- package/src/presets/implementations/gatsby.ts +0 -13
- package/src/presets/implementations/next.ts +0 -13
- package/src/presets/implementations/sveltekit.ts +0 -13
- package/src/presets/implementations/vite.ts +0 -13
- package/src/presets/index.ts +0 -18
- package/src/presets/preset-base.ts +0 -18
- package/tsconfig.json +0 -19
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="@fastly/js-compute" />
|
|
2
|
+
import { AssetsMap } from "./types.js";
|
|
3
|
+
export declare class Assets {
|
|
4
|
+
readonly assetsMap: AssetsMap;
|
|
5
|
+
constructor(assetsMap: AssetsMap);
|
|
6
|
+
serveAsset(event: FetchEvent, pathPrefix?: string): Response | null;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,qBAAa,MAAM;IACjB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAIzB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,GAAE,MAAW;CAqB7D"}
|
package/build/assets.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class Assets {
|
|
2
|
+
constructor(assetsMap) {
|
|
3
|
+
this.assetsMap = assetsMap;
|
|
4
|
+
}
|
|
5
|
+
serveAsset(event, pathPrefix = '') {
|
|
6
|
+
const { request } = event;
|
|
7
|
+
const { pathname } = new URL(request.url);
|
|
8
|
+
const asset = this.assetsMap[`${pathPrefix}${pathname}`];
|
|
9
|
+
if (!asset) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
// Aggressive caching for static files, and no caching for everything else.
|
|
13
|
+
const headers = {
|
|
14
|
+
'Cache-Control': asset.isStatic ? 'max-age=31536000' : 'no-cache',
|
|
15
|
+
};
|
|
16
|
+
if (asset.contentType != null) {
|
|
17
|
+
headers['Content-Type'] = asset.contentType;
|
|
18
|
+
}
|
|
19
|
+
return new Response(asset.content, {
|
|
20
|
+
status: 200,
|
|
21
|
+
headers,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../src/build-static.ts"],"names":[],"mappings":"AAcA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAchD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAoN5F"}
|
package/build/build-static.js
CHANGED
|
@@ -71,9 +71,6 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
71
71
|
const defaultContentTypes = await import(defaultContentTypesJsSrcPath);
|
|
72
72
|
// Load content types
|
|
73
73
|
const finalContentTypes = defaultContentTypes.mergeContentTypes((_c = config.contentTypes) !== null && _c !== void 0 ? _c : []);
|
|
74
|
-
// Update the target file too, so webpack can see it.
|
|
75
|
-
const defaultContentTypesJsPath = path.resolve('./default-content-types.cjs');
|
|
76
|
-
fs.copyFileSync(defaultContentTypesJsSrcPath, defaultContentTypesJsPath);
|
|
77
74
|
const DEFAULT_INCLUDE_DIRS = [
|
|
78
75
|
'./.well-known'
|
|
79
76
|
];
|
package/build/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/build/cli.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import commandLineArgs from "command-line-args";
|
|
3
|
+
import { initApp } from "./init-app.js";
|
|
4
|
+
import { buildStaticLoader } from "./build-static.js";
|
|
5
|
+
const optionDefinitions = [
|
|
6
|
+
// (optional) Should be one of:
|
|
7
|
+
// - cra (or create-react-app)
|
|
8
|
+
// - vite
|
|
9
|
+
// - sveltekit
|
|
10
|
+
// - next
|
|
11
|
+
// - gatsby
|
|
12
|
+
// - docusaurus
|
|
13
|
+
{ name: 'preset', type: String, },
|
|
14
|
+
{ name: 'build-static', type: Boolean },
|
|
15
|
+
{ name: 'suppress-framework-warnings', type: Boolean },
|
|
16
|
+
{ name: 'output', alias: 'o', type: String, defaultValue: './compute-js', },
|
|
17
|
+
{ name: 'public-dir', type: String, },
|
|
18
|
+
{ name: 'static-dir', type: String, },
|
|
19
|
+
// List of files to automatically use as index, for example, index.html,index.htm
|
|
20
|
+
// If a request comes in but the route does not exist, we check the route
|
|
21
|
+
// plus a slash plus the items in this array.
|
|
22
|
+
{
|
|
23
|
+
name: 'auto-index',
|
|
24
|
+
type: (val) => {
|
|
25
|
+
if (val == null) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const values = val
|
|
29
|
+
.split(',')
|
|
30
|
+
.map(x => x.trim())
|
|
31
|
+
.filter(x => x !== '');
|
|
32
|
+
return values.length > 0 ? values : null;
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
// List of extensions to apply to a path name, for example, if
|
|
36
|
+
// http://example.com/about is requested, we can respond with http://example.com/about.html
|
|
37
|
+
{
|
|
38
|
+
name: 'auto-ext',
|
|
39
|
+
type: (val) => {
|
|
40
|
+
if (val == null) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const values = val
|
|
44
|
+
.split(',')
|
|
45
|
+
.map(x => x.trim())
|
|
46
|
+
.map(x => {
|
|
47
|
+
while (x.startsWith('.')) {
|
|
48
|
+
x = x.slice(1);
|
|
49
|
+
}
|
|
50
|
+
return '.' + x;
|
|
51
|
+
})
|
|
52
|
+
.filter(x => x !== '');
|
|
53
|
+
return values.length > 0 ? values : null;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{ name: 'spa', type: String, },
|
|
57
|
+
{ name: 'not-found-page', type: String, },
|
|
58
|
+
{ name: 'name', type: String, },
|
|
59
|
+
{ name: 'author', type: String, },
|
|
60
|
+
{ name: 'description', type: String, },
|
|
61
|
+
// Fastly Service ID to be added to the fastly.toml that is generated.
|
|
62
|
+
{ name: 'service-id', type: String },
|
|
63
|
+
];
|
|
64
|
+
const commandLineValues = commandLineArgs(optionDefinitions);
|
|
65
|
+
console.log("Fastly Compute@Edge JavaScript Static Publisher");
|
|
66
|
+
let mode = 'init-app';
|
|
67
|
+
if (commandLineValues['build-static']) {
|
|
68
|
+
mode = 'build-static';
|
|
69
|
+
}
|
|
70
|
+
switch (mode) {
|
|
71
|
+
case 'build-static':
|
|
72
|
+
await buildStaticLoader(commandLineValues);
|
|
73
|
+
break;
|
|
74
|
+
case 'init-app':
|
|
75
|
+
initApp(commandLineValues);
|
|
76
|
+
break;
|
|
77
|
+
}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -1,77 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { initApp } from "./init-app.js";
|
|
4
|
-
import { buildStaticLoader } from "./build-static.js";
|
|
5
|
-
const optionDefinitions = [
|
|
6
|
-
// (optional) Should be one of:
|
|
7
|
-
// - cra (or create-react-app)
|
|
8
|
-
// - vite
|
|
9
|
-
// - sveltekit
|
|
10
|
-
// - next
|
|
11
|
-
// - gatsby
|
|
12
|
-
// - docusaurus
|
|
13
|
-
{ name: 'preset', type: String, },
|
|
14
|
-
{ name: 'build-static', type: Boolean },
|
|
15
|
-
{ name: 'suppress-framework-warnings', type: Boolean },
|
|
16
|
-
{ name: 'output', alias: 'o', type: String, defaultValue: './compute-js', },
|
|
17
|
-
{ name: 'public-dir', type: String, },
|
|
18
|
-
{ name: 'static-dir', type: String, },
|
|
19
|
-
// List of files to automatically use as index, for example, index.html,index.htm
|
|
20
|
-
// If a request comes in but the route does not exist, we check the route
|
|
21
|
-
// plus a slash plus the items in this array.
|
|
22
|
-
{
|
|
23
|
-
name: 'auto-index',
|
|
24
|
-
type: (val) => {
|
|
25
|
-
if (val == null) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
const values = val
|
|
29
|
-
.split(',')
|
|
30
|
-
.map(x => x.trim())
|
|
31
|
-
.filter(x => x !== '');
|
|
32
|
-
return values.length > 0 ? values : null;
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
// List of extensions to apply to a path name, for example, if
|
|
36
|
-
// http://example.com/about is requested, we can respond with http://example.com/about.html
|
|
37
|
-
{
|
|
38
|
-
name: 'auto-ext',
|
|
39
|
-
type: (val) => {
|
|
40
|
-
if (val == null) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const values = val
|
|
44
|
-
.split(',')
|
|
45
|
-
.map(x => x.trim())
|
|
46
|
-
.map(x => {
|
|
47
|
-
while (x.startsWith('.')) {
|
|
48
|
-
x = x.slice(1);
|
|
49
|
-
}
|
|
50
|
-
return '.' + x;
|
|
51
|
-
})
|
|
52
|
-
.filter(x => x !== '');
|
|
53
|
-
return values.length > 0 ? values : null;
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
{ name: 'spa', type: String, },
|
|
57
|
-
{ name: 'not-found-page', type: String, },
|
|
58
|
-
{ name: 'name', type: String, },
|
|
59
|
-
{ name: 'author', type: String, },
|
|
60
|
-
{ name: 'description', type: String, },
|
|
61
|
-
// Fastly Service ID to be added to the fastly.toml that is generated.
|
|
62
|
-
{ name: 'service-id', type: String },
|
|
63
|
-
];
|
|
64
|
-
const commandLineValues = commandLineArgs(optionDefinitions);
|
|
65
|
-
console.log("Fastly Compute@Edge JavaScript Static Publisher");
|
|
66
|
-
let mode = 'init-app';
|
|
67
|
-
if (commandLineValues['build-static']) {
|
|
68
|
-
mode = 'build-static';
|
|
69
|
-
}
|
|
70
|
-
switch (mode) {
|
|
71
|
-
case 'build-static':
|
|
72
|
-
await buildStaticLoader(commandLineValues);
|
|
73
|
-
break;
|
|
74
|
-
case 'init-app':
|
|
75
|
-
initApp(commandLineValues);
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
1
|
+
/// <reference types="@fastly/js-compute" />
|
|
2
|
+
export { StaticAssets } from './static-assets.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../src/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAiDvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAyR5D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IPresetBase } from '../preset-base.js';
|
|
2
|
+
export declare class CreateReactAppPreset implements IPresetBase {
|
|
3
|
+
name: string;
|
|
4
|
+
defaultOptions: {
|
|
5
|
+
'public-dir': string;
|
|
6
|
+
'static-dir': string;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
};
|
|
10
|
+
check(packageJson: any): boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class CreateReactAppEjectedPreset extends CreateReactAppPreset {
|
|
13
|
+
name: string;
|
|
14
|
+
check(): boolean;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=create-react-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-react-app.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/create-react-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,oBAAqB,YAAW,WAAW;IACtD,IAAI,SAAsB;IAC1B,cAAc;;;;;MAKZ;IAEF,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO;CAejC;AAED,qBAAa,2BAA4B,SAAQ,oBAAoB;IACnE,IAAI,SAAgC;IACpC,KAAK;CAGN"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IPresetBase } from '../preset-base.js';
|
|
2
|
+
export declare class DocusaurusPreset implements IPresetBase {
|
|
3
|
+
name: string;
|
|
4
|
+
defaultOptions: {
|
|
5
|
+
'public-dir': string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
};
|
|
9
|
+
check(): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=docusaurus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docusaurus.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/docusaurus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,gBAAiB,YAAW,WAAW;IAClD,IAAI,SAAgB;IACpB,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IPresetBase } from '../preset-base.js';
|
|
2
|
+
export declare class GatsbyPreset implements IPresetBase {
|
|
3
|
+
name: string;
|
|
4
|
+
defaultOptions: {
|
|
5
|
+
'public-dir': string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
};
|
|
9
|
+
check(): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=gatsby.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gatsby.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/gatsby.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,YAAa,YAAW,WAAW;IAC9C,IAAI,SAAY;IAChB,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IPresetBase } from '../preset-base.js';
|
|
2
|
+
export declare class NextJsPreset implements IPresetBase {
|
|
3
|
+
name: string;
|
|
4
|
+
defaultOptions: {
|
|
5
|
+
'public-dir': string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
};
|
|
9
|
+
check(): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=next.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,YAAa,YAAW,WAAW;IAC9C,IAAI,SAAa;IACjB,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IPresetBase } from '../preset-base.js';
|
|
2
|
+
export declare class SvelteKitPreset implements IPresetBase {
|
|
3
|
+
name: string;
|
|
4
|
+
defaultOptions: {
|
|
5
|
+
'public-dir': string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
};
|
|
9
|
+
check(): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=sveltekit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sveltekit.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/sveltekit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,eAAgB,YAAW,WAAW;IACjD,IAAI,SAAe;IACnB,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IPresetBase } from '../preset-base.js';
|
|
2
|
+
export declare class VitePreset implements IPresetBase {
|
|
3
|
+
name: string;
|
|
4
|
+
defaultOptions: {
|
|
5
|
+
'public-dir': string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
};
|
|
9
|
+
check(): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=vite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,UAAW,YAAW,WAAW;IAC5C,IAAI,SAAU;IACd,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQ/C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAS,WAAW,CASxD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare type AppOptions = {
|
|
2
|
+
'public-dir': string | undefined;
|
|
3
|
+
'static-dir': string | undefined;
|
|
4
|
+
spa: string | null | undefined;
|
|
5
|
+
'not-found-page': string | null | undefined;
|
|
6
|
+
'auto-index': string[] | null | undefined;
|
|
7
|
+
'auto-ext': string[] | null | undefined;
|
|
8
|
+
name: string;
|
|
9
|
+
author: string;
|
|
10
|
+
description: string;
|
|
11
|
+
'service-id': string | undefined;
|
|
12
|
+
};
|
|
13
|
+
export interface IPresetBase {
|
|
14
|
+
name: string;
|
|
15
|
+
defaultOptions: Partial<AppOptions>;
|
|
16
|
+
check(packageJson: any | null, options: AppOptions): boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=preset-base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset-base.d.ts","sourceRoot":"","sources":["../../src/presets/preset-base.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU,GAAG;IACvB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACpC,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC;CAC9D"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="@fastly/js-compute" />
|
|
2
|
+
import { AssetsMap } from "./types.js";
|
|
3
|
+
export declare class StaticAssets {
|
|
4
|
+
readonly assetsMap: AssetsMap;
|
|
5
|
+
constructor(assetsMap: AssetsMap);
|
|
6
|
+
serveAsset(event: FetchEvent, pathPrefix?: string): Response | null;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=static-assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-assets.d.ts","sourceRoot":"","sources":["../src/static-assets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,qBAAa,YAAY;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAIzB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,GAAE,MAAW;CAqB7D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class StaticAssets {
|
|
2
|
+
constructor(assetsMap) {
|
|
3
|
+
this.assetsMap = assetsMap;
|
|
4
|
+
}
|
|
5
|
+
serveAsset(event, pathPrefix = '') {
|
|
6
|
+
const { request } = event;
|
|
7
|
+
const { pathname } = new URL(request.url);
|
|
8
|
+
const asset = this.assetsMap[`${pathPrefix}${pathname}`];
|
|
9
|
+
if (!asset) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
// Aggressive caching for static files, and no caching for everything else.
|
|
13
|
+
const headers = {
|
|
14
|
+
'Cache-Control': asset.isStatic ? 'max-age=31536000' : 'no-cache',
|
|
15
|
+
};
|
|
16
|
+
if (asset.contentType != null) {
|
|
17
|
+
headers['Content-Type'] = asset.contentType;
|
|
18
|
+
}
|
|
19
|
+
return new Response(asset.content, {
|
|
20
|
+
status: 200,
|
|
21
|
+
headers,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
declare type TestFn = (name: string) => boolean;
|
|
3
|
+
export declare type ContentTypeDef = {
|
|
4
|
+
test: RegExp | TestFn;
|
|
5
|
+
type: string;
|
|
6
|
+
binary?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare type ContentTypeMatch = {
|
|
9
|
+
type: string;
|
|
10
|
+
binary: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare type DefaultContentTypesModule = {
|
|
13
|
+
mergeContentTypes: (contentTypes: ContentTypeDef[]) => ContentTypeDef[];
|
|
14
|
+
testFileContentType: (contentTypes: ContentTypeDef[], file: string) => ContentTypeMatch;
|
|
15
|
+
};
|
|
16
|
+
export declare type Asset = {
|
|
17
|
+
contentType: string;
|
|
18
|
+
content: Buffer | string;
|
|
19
|
+
module: unknown | null;
|
|
20
|
+
isStatic: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare type AssetsMap = {
|
|
23
|
+
[filePath: string]: Asset;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,aAAK,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAExC,oBAAY,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,oBAAY,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,CAAC;IACxE,mBAAmB,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,EAAE,IAAI,EAAE,MAAM,KAAK,gBAAgB,CAAC;CACzF,CAAC;AAEF,oBAAY,KAAK,GAAG;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;CAC3B,CAAC"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/compute-js-static-publish",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0-alpha.0",
|
|
5
5
|
"description": "Static Publisher for Compute@Edge JavaScript",
|
|
6
6
|
"main": "./build/index.js",
|
|
7
|
+
"types": "./build/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"prepack": "npm run build",
|
|
9
10
|
"build": "tsc",
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
12
|
},
|
|
12
13
|
"bin": {
|
|
13
|
-
"compute-js-static-publish": "./build/
|
|
14
|
-
"compute-js-build-static-loader": "./build/build-static.js"
|
|
14
|
+
"compute-js-static-publish": "./build/cli.js"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/fastly/compute-js-static-publish#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"@fastly/js-compute": "^0.5.4",
|
|
33
34
|
"command-line-args": "^5.2.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
@@ -39,5 +40,13 @@
|
|
|
39
40
|
},
|
|
40
41
|
"engines": {
|
|
41
42
|
"node": ">=14.8"
|
|
42
|
-
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"build",
|
|
46
|
+
"resources",
|
|
47
|
+
"LICENSE",
|
|
48
|
+
"package.json",
|
|
49
|
+
"README.md",
|
|
50
|
+
"SECURITY.md"
|
|
51
|
+
]
|
|
43
52
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="Go" enabled="true" />
|
|
4
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
5
|
-
<exclude-output />
|
|
6
|
-
<content url="file://$MODULE_DIR$">
|
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/build" />
|
|
8
|
-
</content>
|
|
9
|
-
<orderEntry type="inheritedJdk" />
|
|
10
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
-
</component>
|
|
12
|
-
</module>
|
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/compute-js-static-publish.iml" filepath="$PROJECT_DIR$/.idea/compute-js-static-publish.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|