@fastly/compute-js-static-publish 3.0.0 → 3.1.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/build-static.d.ts.map +1 -1
- package/build/build-static.js +22 -9
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/init-app.d.ts.map +1 -1
- package/build/init-app.js +3 -1
- package/build/types.d.ts +13 -0
- package/build/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/resources/index.js +2 -2
- package/resources/statics.d.ts +25 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../src/build-static.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../src/build-static.ts"],"names":[],"mappings":"AAkBA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAchD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAqP5F"}
|
package/build/build-static.js
CHANGED
|
@@ -21,7 +21,7 @@ function getFiles(results, dir) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
export async function buildStaticLoader(commandLineValues) {
|
|
24
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
24
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
25
25
|
const { 'suppress-framework-warnings': suppressFrameworkWarnings } = commandLineValues;
|
|
26
26
|
const displayFrameworkWarnings = !suppressFrameworkWarnings;
|
|
27
27
|
console.log("🚀 Building loader...");
|
|
@@ -65,8 +65,8 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
const excludeRoots = excludeDirs.map(dir => path.resolve(publicDirRoot, dir));
|
|
68
|
-
// Load defaultContentTypes module
|
|
69
68
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
69
|
+
// Load defaultContentTypes module
|
|
70
70
|
const defaultContentTypesJsSrcPath = path.resolve(__dirname, '../resources/default-content-types.cjs');
|
|
71
71
|
const defaultContentTypes = await import(defaultContentTypesJsSrcPath);
|
|
72
72
|
// Load content types
|
|
@@ -84,7 +84,7 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
const includeRoots = includeDirs.map(dir => path.resolve(publicDirRoot, dir));
|
|
87
|
-
const excludeTest = config.excludeTest;
|
|
87
|
+
const excludeTest = (_f = config.excludeTest) !== null && _f !== void 0 ? _f : null;
|
|
88
88
|
const files = results
|
|
89
89
|
.filter(file => {
|
|
90
90
|
// Exclude files that come from C@E app dir
|
|
@@ -108,7 +108,7 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
108
108
|
.filter(file => {
|
|
109
109
|
return excludeTest == null || !excludeTest(file);
|
|
110
110
|
});
|
|
111
|
-
const moduleTest = config.moduleTest;
|
|
111
|
+
const moduleTest = (_g = config.moduleTest) !== null && _g !== void 0 ? _g : null;
|
|
112
112
|
const knownAssets = {};
|
|
113
113
|
// Create "static content" dir that will be used to hold a copy of static files
|
|
114
114
|
// NOTE: this is needed because includeBytes doesn't seem to be able to traverse
|
|
@@ -116,7 +116,11 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
116
116
|
const staticContentDir = './src/static-content';
|
|
117
117
|
fs.rmSync(staticContentDir, { recursive: true, force: true });
|
|
118
118
|
fs.mkdirSync(staticContentDir, { recursive: true });
|
|
119
|
-
let fileContents =
|
|
119
|
+
let fileContents = `/*
|
|
120
|
+
* Generated by @fastly/compute-js-static-publish.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
`;
|
|
120
124
|
fileContents += 'import { StaticAssets } from "@fastly/compute-js-static-publish";\n';
|
|
121
125
|
fileContents += 'import { includeBytes } from "fastly:experimental";\n';
|
|
122
126
|
// If any files need to be loaded as modules, import them now.
|
|
@@ -175,7 +179,7 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
175
179
|
fileContents += ` ${JSON.stringify(filePath)}: { contentType: ${JSON.stringify(type)}, content: ${content}, module: ${module}, isStatic: ${JSON.stringify(isStatic)} },\n`;
|
|
176
180
|
}
|
|
177
181
|
fileContents += '};\n';
|
|
178
|
-
let spaFile = (
|
|
182
|
+
let spaFile = (_h = config.spa) !== null && _h !== void 0 ? _h : false;
|
|
179
183
|
if (spaFile) {
|
|
180
184
|
console.log(`✔️ Application SPA file '${spaFile}'.`);
|
|
181
185
|
if (!knownAssets[spaFile] || knownAssets[spaFile].contentType !== 'text/html') {
|
|
@@ -191,7 +195,7 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
191
195
|
}
|
|
192
196
|
}
|
|
193
197
|
fileContents += `\nexport const spaFile = ${JSON.stringify(spaFile)};\n`;
|
|
194
|
-
let notFoundPageFile = (
|
|
198
|
+
let notFoundPageFile = (_j = config.notFoundPage) !== null && _j !== void 0 ? _j : false;
|
|
195
199
|
if (notFoundPageFile) {
|
|
196
200
|
console.log(`✔️ Application 'not found (404)' file '${notFoundPageFile}'.`);
|
|
197
201
|
if (!knownAssets[notFoundPageFile] || knownAssets[notFoundPageFile].contentType !== 'text/html') {
|
|
@@ -207,11 +211,20 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
207
211
|
}
|
|
208
212
|
}
|
|
209
213
|
fileContents += `\nexport const notFoundPageFile = ${JSON.stringify(notFoundPageFile)};\n`;
|
|
210
|
-
let autoIndex = (
|
|
214
|
+
let autoIndex = (_k = config.autoIndex) !== null && _k !== void 0 ? _k : false;
|
|
211
215
|
fileContents += `\nexport const autoIndex = ${JSON.stringify(autoIndex)};\n`;
|
|
212
|
-
let autoExt = (
|
|
216
|
+
let autoExt = (_l = config.autoExt) !== null && _l !== void 0 ? _l : false;
|
|
213
217
|
fileContents += `\nexport const autoExt = ${JSON.stringify(autoExt)};\n`;
|
|
214
218
|
fileContents += '\nexport const staticAssets = new StaticAssets(assets);\n';
|
|
215
219
|
fs.writeFileSync('./src/statics.js', fileContents);
|
|
216
220
|
console.log("✅ Wrote static file loader for " + files.length + " file(s).");
|
|
221
|
+
// Copy Types file for static file loader
|
|
222
|
+
try {
|
|
223
|
+
const staticsTypeFile = path.resolve(__dirname, '../resources/statics.d.ts');
|
|
224
|
+
fs.copyFileSync(staticsTypeFile, './src/statics.d.ts');
|
|
225
|
+
console.log("✅ Wrote static file loader types file statics.d.ts.");
|
|
226
|
+
}
|
|
227
|
+
catch (_m) {
|
|
228
|
+
console.log("⚠️ Notice: could not wrote static file loader types file statics.d.ts.");
|
|
229
|
+
}
|
|
217
230
|
}
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/build/init-app.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,QA6R5D"}
|
package/build/init-app.js
CHANGED
|
@@ -161,6 +161,7 @@ export function initApp(commandLineValues) {
|
|
|
161
161
|
/bin
|
|
162
162
|
/pkg
|
|
163
163
|
/src/statics.js
|
|
164
|
+
/src/statics.d.ts
|
|
164
165
|
/src/static-content
|
|
165
166
|
`;
|
|
166
167
|
const gitIgnorePath = path.resolve(computeJsDir, '.gitignore');
|
|
@@ -173,7 +174,7 @@ export function initApp(commandLineValues) {
|
|
|
173
174
|
"description": ${JSON.stringify(description)},
|
|
174
175
|
"author": ${JSON.stringify(author)},
|
|
175
176
|
"devDependencies": {
|
|
176
|
-
"@fastly/compute-js-static-publish": "^
|
|
177
|
+
"@fastly/compute-js-static-publish": "^3.0.1",
|
|
177
178
|
"@fastly/expressly": "^1.0.0-beta.2",
|
|
178
179
|
"webpack": "^5.75.0",
|
|
179
180
|
"webpack-cli": "^5.0.0"
|
|
@@ -238,6 +239,7 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
|
|
|
238
239
|
notFoundFileRel = '/' + path.relative(publicDir, notFoundPageFilename);
|
|
239
240
|
}
|
|
240
241
|
const staticPublishJsContent = `\
|
|
242
|
+
/** @type {import('@fastly/compute-js-static-publish').Config} */
|
|
241
243
|
module.exports = {
|
|
242
244
|
publicDir: ${JSON.stringify(publicDirRel)},
|
|
243
245
|
excludeDirs: [ './node_modules' ],
|
package/build/types.d.ts
CHANGED
|
@@ -21,5 +21,18 @@ export declare type Asset = {
|
|
|
21
21
|
export declare type AssetsMap = {
|
|
22
22
|
[filePath: string]: Asset;
|
|
23
23
|
};
|
|
24
|
+
export declare type Config = {
|
|
25
|
+
publicDir: string;
|
|
26
|
+
excludeDirs?: string[] | null;
|
|
27
|
+
includeDirs?: string[] | null;
|
|
28
|
+
staticDirs?: string[] | null;
|
|
29
|
+
excludeTest?: ((path: string) => boolean) | null;
|
|
30
|
+
moduleTest?: ((path: string) => boolean) | null;
|
|
31
|
+
spa?: string | null;
|
|
32
|
+
autoIndex?: string[] | false | null;
|
|
33
|
+
autoExt?: string[] | false | null;
|
|
34
|
+
notFoundPage?: string | false | null;
|
|
35
|
+
contentTypes?: ContentTypeDef[] | null;
|
|
36
|
+
};
|
|
24
37
|
export {};
|
|
25
38
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +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,WAAW,GAAG,MAAM,CAAC;IAC9B,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"}
|
|
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,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M,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;IACrC,YAAY,CAAC,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;CACxC,CAAC"}
|
package/package.json
CHANGED
package/resources/index.js
CHANGED
|
@@ -15,7 +15,7 @@ function getMatchingRequestPath(path) {
|
|
|
15
15
|
|
|
16
16
|
// ... or, we can try auto-ext:
|
|
17
17
|
// looks for an asset that has the specified suffix (usually extension, such as .html)
|
|
18
|
-
if(autoExt
|
|
18
|
+
if(Array.isArray(autoExt)) {
|
|
19
19
|
for (const extEntry of autoExt) {
|
|
20
20
|
let pathWithExt = path + extEntry;
|
|
21
21
|
if (staticAssets.getAsset(pathWithExt) != null) {
|
|
@@ -34,7 +34,7 @@ function getMatchingRequestPath(path) {
|
|
|
34
34
|
dir = dir.slice(0, -1);
|
|
35
35
|
}
|
|
36
36
|
dir = dir + '/';
|
|
37
|
-
if(autoIndex
|
|
37
|
+
if(Array.isArray(autoIndex)) {
|
|
38
38
|
for (const indexEntry of autoIndex) {
|
|
39
39
|
let indexPath = dir + indexEntry;
|
|
40
40
|
if (staticAssets.getAsset(indexPath) != null) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Generated by @fastly/compute-js-static-publish.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
type AssetBase = {
|
|
6
|
+
contentType: string,
|
|
7
|
+
module: any | null,
|
|
8
|
+
isStatic: boolean,
|
|
9
|
+
};
|
|
10
|
+
type StringAsset = AssetBase & {
|
|
11
|
+
type: 'string',
|
|
12
|
+
content: string,
|
|
13
|
+
};
|
|
14
|
+
type BinaryAsset = AssetBase & {
|
|
15
|
+
type: 'binary',
|
|
16
|
+
content: Uint8Array,
|
|
17
|
+
};
|
|
18
|
+
type Asset = StringAsset | BinaryAsset;
|
|
19
|
+
import { StaticAssets } from "@fastly/compute-js-static-publish";
|
|
20
|
+
export declare const assets: Record<string, Asset>;
|
|
21
|
+
export declare const spaFile: string | false;
|
|
22
|
+
export declare const notFoundPageFile: string | false;
|
|
23
|
+
export declare const autoIndex: string[] | false;
|
|
24
|
+
export declare const autoExt: string[] | false;
|
|
25
|
+
export declare const staticAssets: StaticAssets;
|