@fastly/compute-js-static-publish
Advanced tools
Comparing version 2.4.2 to 3.0.0
@@ -113,37 +113,24 @@ // This program builds static resources out of the files in the | ||
const knownAssets = {}; | ||
// Create "static content" dir that will be used to hold a copy of static files | ||
// NOTE: this is needed because includeBytes doesn't seem to be able to traverse | ||
// up to parent dir of Compute project. | ||
const staticContentDir = './src/static-content'; | ||
fs.rmSync(staticContentDir, { recursive: true, force: true }); | ||
fs.mkdirSync(staticContentDir, { recursive: true }); | ||
let fileContents = ''; | ||
for (const [index, file] of files.entries()) { | ||
const relativeFilePath = path.relative('./src', file); | ||
const contentDef = defaultContentTypes.testFileContentType(finalContentTypes, file); | ||
const filePath = file.slice(publicDirRoot.length); | ||
const type = contentDef === null || contentDef === void 0 ? void 0 : contentDef.type; | ||
const isStatic = staticRoots.some(root => file.startsWith(root)); | ||
let query; | ||
if (contentDef == null || contentDef.binary) { | ||
query = '?staticBinary'; | ||
fileContents += 'import { StaticAssets } from "@fastly/compute-js-static-publish";\n'; | ||
fileContents += 'import { includeBytes } from "fastly:experimental";\n'; | ||
// If any files need to be loaded as modules, import them now. | ||
const loadAsModule = []; | ||
if (moduleTest != null) { | ||
for (const [index, file] of files.entries()) { | ||
const relativeFilePath = path.relative('./src', file); | ||
const filePath = file.slice(publicDirRoot.length); | ||
if (moduleTest(filePath)) { | ||
loadAsModule[index] = true; | ||
fileContents += `import * as fileModule${index} from "${relativeFilePath}";\n`; | ||
} | ||
} | ||
else { | ||
query = '?staticText'; | ||
} | ||
fileContents += `import file${index} from "${relativeFilePath}${query}";\n`; | ||
let loadModule = false; | ||
if (moduleTest != null && moduleTest(filePath)) { | ||
loadModule = true; | ||
fileContents += `import * as fileModule${index} from "${relativeFilePath}";\n`; | ||
} | ||
knownAssets[filePath] = { contentType: type, isStatic, loadModule, }; | ||
} | ||
fileContents += 'import { StaticAssets } from "@fastly/compute-js-static-publish";\n'; | ||
fileContents += ` | ||
function fromBase64(data) { | ||
const raw = atob(data); | ||
const rawLength = raw.length; | ||
const array = new ArrayBuffer(rawLength); | ||
const view = new Uint8Array(array); | ||
for (let i = 0; i < rawLength; i++) { | ||
view[i] = raw.charCodeAt(i); | ||
} | ||
return array; | ||
} | ||
`; | ||
fileContents += 'const textDecoder = new TextDecoder();\n'; | ||
fileContents += `\nexport const assets = {\n`; | ||
@@ -153,3 +140,4 @@ for (const [index, file] of files.entries()) { | ||
const filePath = file.slice(publicDirRoot.length); | ||
const { contentType: type, isStatic, loadModule } = knownAssets[filePath]; | ||
const type = contentDef === null || contentDef === void 0 ? void 0 : contentDef.type; | ||
const isStatic = staticRoots.some(root => file.startsWith(root)); | ||
if (contentDef != null) { | ||
@@ -163,11 +151,23 @@ console.log('✔️ ' + filePath + ': ' + JSON.stringify(type) + (isStatic ? ' [STATIC]' : '')); | ||
} | ||
let content; | ||
// Serve static files by copying them into the static content dir and using includeBytes() | ||
let staticFileExt, staticFileTypeDesc, isBinary; | ||
if (contentDef == null || contentDef.binary) { | ||
content = 'fromBase64(file' + index + ')'; | ||
staticFileExt = '.bin'; | ||
staticFileTypeDesc = 'binary'; | ||
isBinary = true; | ||
} | ||
else { | ||
content = 'String(file' + index + ')'; | ||
staticFileExt = '.txt'; | ||
staticFileTypeDesc = 'text'; | ||
isBinary = false; | ||
} | ||
const staticFilePath = `${staticContentDir}/file${index}${staticFileExt}`; | ||
fs.cpSync(file, staticFilePath); | ||
console.log(`✔️ Copied static ${staticFileTypeDesc} file "${file}" to "${staticFilePath}".`); | ||
let content = `includeBytes("${staticFilePath}")`; | ||
if (!isBinary) { | ||
content = `textDecoder.decode(${content})`; | ||
} | ||
let module; | ||
if (loadModule) { | ||
if (loadAsModule[index]) { | ||
module = 'fileModule' + index; | ||
@@ -174,0 +174,0 @@ } |
@@ -164,2 +164,3 @@ // This program creates a Compute@Edge JavaScript application | ||
/src/statics.js | ||
/src/static-content | ||
`; | ||
@@ -177,3 +178,3 @@ const gitIgnorePath = path.resolve(computeJsDir, '.gitignore'); | ||
"@fastly/compute-js-static-publish": "^2.4.0", | ||
"@fastly/expressly": "^1.0.0-alpha.7", | ||
"@fastly/expressly": "^1.0.0-beta.2", | ||
"webpack": "^5.75.0", | ||
@@ -183,3 +184,3 @@ "webpack-cli": "^5.0.0" | ||
"dependencies": { | ||
"@fastly/js-compute": "^0.5.12" | ||
"@fastly/js-compute": "^1.0.1" | ||
}, | ||
@@ -186,0 +187,0 @@ "engines": { |
{ | ||
"name": "@fastly/compute-js-static-publish", | ||
"type": "module", | ||
"version": "2.4.2", | ||
"version": "3.0.0", | ||
"description": "Static Publisher for Compute@Edge JavaScript", | ||
@@ -33,3 +33,3 @@ "main": "./build/index.js", | ||
"dependencies": { | ||
"@fastly/js-compute": "^0.5.12", | ||
"@fastly/js-compute": "^1.0.1", | ||
"command-line-args": "^5.2.1" | ||
@@ -36,0 +36,0 @@ }, |
@@ -5,2 +5,7 @@ # Static Publisher for JavaScript on Compute@Edge | ||
## Breaking Changes | ||
v3.0 makes some updates that require changes to some files. If you've been using your `compute-js-static-publisher` application without modification, you may simply re-scaffold your application. | ||
Otherwise, you can make some updates to your files. See [MIGRATING](#migrating) below for details. | ||
## How it works | ||
@@ -98,2 +103,59 @@ | ||
## Migrating | ||
If you've updated your project to 3.0.0 or newer of `@fastly/compute-js-static-publish`, and it was scaffolded a version of this tool older than 3.0.0, you'll need to either re-scaffold your project, or make some changes to your application. | ||
If you wish to modify your application, make the following changes: | ||
* `webpack.config.js` | ||
* Add a new `externals` array to the bottom if it doesn't exist already, and add the following entry: | ||
```javascript | ||
module.exports = { | ||
/* ... other config ... */ | ||
externals: [ | ||
({request,}, callback) => { | ||
if (/^fastly:.*$/.test(request)) { | ||
return callback(null, 'commonjs ' + request); | ||
} | ||
callback(); | ||
} | ||
], | ||
} | ||
``` | ||
* Remove the following code from the `module.rules` array. | ||
```javascript | ||
{ | ||
// asset/source exports the source code of the asset. | ||
resourceQuery: /staticText/, | ||
type: "asset/source", | ||
}, | ||
{ | ||
// asset/inline exports the raw bytes of the asset. | ||
// We base64 encode them here | ||
resourceQuery: /staticBinary/, | ||
type: "asset/inline", | ||
generator: { | ||
/** | ||
* @param {Buffer} content | ||
* @returns {string} | ||
*/ | ||
dataUrl: content => { | ||
return content.toString('base64'); | ||
}, | ||
} | ||
}, | ||
``` | ||
* `.gitignore` | ||
* Add the following entry: | ||
```gitignore | ||
/src/static-content | ||
``` | ||
## Troubleshooting | ||
@@ -100,0 +162,0 @@ |
const path = require("path"); | ||
const webpack = require("webpack"); | ||
const { ProvidePlugin } = webpack; | ||
@@ -8,3 +6,3 @@ module.exports = { | ||
optimization: { | ||
minimize: false | ||
minimize: true | ||
}, | ||
@@ -27,22 +25,2 @@ target: "webworker", | ||
}, | ||
{ | ||
// asset/source exports the source code of the asset. | ||
resourceQuery: /staticText/, | ||
type: "asset/source", | ||
}, | ||
{ | ||
// asset/inline exports the raw bytes of the asset. | ||
// We base64 encode them here | ||
resourceQuery: /staticBinary/, | ||
type: "asset/inline", | ||
generator: { | ||
/** | ||
* @param {Buffer} content | ||
* @returns {string} | ||
*/ | ||
dataUrl: content => { | ||
return content.toString('base64'); | ||
}, | ||
} | ||
}, | ||
], | ||
@@ -55,2 +33,10 @@ }, | ||
], | ||
externals: [ | ||
({request,}, callback) => { | ||
if (/^fastly:.*$/.test(request)) { | ||
return callback(null, 'commonjs ' + request); | ||
} | ||
callback(); | ||
} | ||
], | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61134
185
1114
+ Added@babel/regjsgen@0.8.0(transitive)
+ Added@bytecodealliance/jco@0.6.1(transitive)
+ Added@bytecodealliance/wizer@1.6.1-beta.4(transitive)
+ Added@bytecodealliance/wizer-darwin-arm64@1.6.1-beta.4(transitive)
+ Added@bytecodealliance/wizer-darwin-x64@1.6.1-beta.4(transitive)
+ Added@bytecodealliance/wizer-linux-x64@1.6.1-beta.4(transitive)
+ Added@bytecodealliance/wizer-win32-x64@1.6.1-beta.4(transitive)
+ Added@esbuild/android-arm@0.17.19(transitive)
+ Added@esbuild/android-arm64@0.17.19(transitive)
+ Added@esbuild/android-x64@0.17.19(transitive)
+ Added@esbuild/darwin-arm64@0.17.19(transitive)
+ Added@esbuild/darwin-x64@0.17.19(transitive)
+ Added@esbuild/freebsd-arm64@0.17.19(transitive)
+ Added@esbuild/freebsd-x64@0.17.19(transitive)
+ Added@esbuild/linux-arm@0.17.19(transitive)
+ Added@esbuild/linux-arm64@0.17.19(transitive)
+ Added@esbuild/linux-ia32@0.17.19(transitive)
+ Added@esbuild/linux-loong64@0.17.19(transitive)
+ Added@esbuild/linux-mips64el@0.17.19(transitive)
+ Added@esbuild/linux-ppc64@0.17.19(transitive)
+ Added@esbuild/linux-riscv64@0.17.19(transitive)
+ Added@esbuild/linux-s390x@0.17.19(transitive)
+ Added@esbuild/linux-x64@0.17.19(transitive)
+ Added@esbuild/netbsd-x64@0.17.19(transitive)
+ Added@esbuild/openbsd-x64@0.17.19(transitive)
+ Added@esbuild/sunos-x64@0.17.19(transitive)
+ Added@esbuild/win32-arm64@0.17.19(transitive)
+ Added@esbuild/win32-ia32@0.17.19(transitive)
+ Added@esbuild/win32-x64@0.17.19(transitive)
+ Added@fastly/js-compute@1.13.0(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedacorn-walk@8.3.4(transitive)
+ Addedesbuild@0.17.19(transitive)
+ Addedjsesc@0.5.0(transitive)
+ Addedmagic-string@0.30.17(transitive)
+ Addedregenerate@1.4.2(transitive)
+ Addedregenerate-unicode-properties@10.2.0(transitive)
+ Addedregexpu-core@5.3.2(transitive)
+ Addedregjsparser@0.9.1(transitive)
+ Addedunicode-canonical-property-names-ecmascript@2.0.1(transitive)
+ Addedunicode-match-property-ecmascript@2.0.0(transitive)
+ Addedunicode-match-property-value-ecmascript@2.2.0(transitive)
+ Addedunicode-property-aliases-ecmascript@2.1.0(transitive)
- Removed@esbuild/android-arm@0.15.18(transitive)
- Removed@esbuild/linux-loong64@0.15.18(transitive)
- Removed@fastly/js-compute@0.5.15(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbl@4.1.0(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedchownr@1.1.4(transitive)
- Removeddecompress-response@6.0.0(transitive)
- Removeddeep-extend@0.6.0(transitive)
- Removeddetect-libc@2.0.3(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedesbuild@0.15.18(transitive)
- Removedesbuild-android-64@0.15.18(transitive)
- Removedesbuild-android-arm64@0.15.18(transitive)
- Removedesbuild-darwin-64@0.15.18(transitive)
- Removedesbuild-darwin-arm64@0.15.18(transitive)
- Removedesbuild-freebsd-64@0.15.18(transitive)
- Removedesbuild-freebsd-arm64@0.15.18(transitive)
- Removedesbuild-linux-32@0.15.18(transitive)
- Removedesbuild-linux-64@0.15.18(transitive)
- Removedesbuild-linux-arm@0.15.18(transitive)
- Removedesbuild-linux-arm64@0.15.18(transitive)
- Removedesbuild-linux-mips64le@0.15.18(transitive)
- Removedesbuild-linux-ppc64le@0.15.18(transitive)
- Removedesbuild-linux-riscv64@0.15.18(transitive)
- Removedesbuild-linux-s390x@0.15.18(transitive)
- Removedesbuild-netbsd-64@0.15.18(transitive)
- Removedesbuild-openbsd-64@0.15.18(transitive)
- Removedesbuild-sunos-64@0.15.18(transitive)
- Removedesbuild-windows-32@0.15.18(transitive)
- Removedesbuild-windows-64@0.15.18(transitive)
- Removedesbuild-windows-arm64@0.15.18(transitive)
- Removedexpand-template@2.0.3(transitive)
- Removedfs-constants@1.0.0(transitive)
- Removedgithub-from-package@0.0.0(transitive)
- Removedieee754@1.2.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedini@1.3.8(transitive)
- Removedmimic-response@3.1.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp-classic@0.5.3(transitive)
- Removednan@2.22.0(transitive)
- Removednapi-build-utils@1.0.2(transitive)
- Removednode-abi@3.71.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedprebuild-install@7.1.2(transitive)
- Removedpump@3.0.2(transitive)
- Removedrc@1.2.8(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@7.6.3(transitive)
- Removedsimple-concat@1.0.1(transitive)
- Removedsimple-get@4.0.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedtar-fs@2.1.1(transitive)
- Removedtar-stream@2.2.0(transitive)
- Removedtree-sitter@0.20.6(transitive)
- Removedtree-sitter-javascript@0.19.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwrappy@1.0.2(transitive)
Updated@fastly/js-compute@^1.0.1