Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastly/compute-js-static-publish

Package Overview
Dependencies
Maintainers
3
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastly/compute-js-static-publish - npm Package Compare versions

Comparing version 2.4.2 to 3.0.0

74

build/build-static.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc