Skip to content

Fs 12113 upgrade to webpack 5 #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: feature/FS-12113
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/deploy_beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup repository env
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: '14.x'
node-version: 18.20.5
registry-url: "https://registry.npmjs.org"
- name: Install deps
run: npm install --ignore-scripts
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.20.0
v18.20.5
41,102 changes: 12,086 additions & 29,016 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"ts-node": "^10.9.1"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.787.0",
"@babel/core": "^7.21.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.23.7",
Expand All @@ -69,9 +70,9 @@
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"assert": "^2.0.0",
"aws-sdk": "^2.1334.0",
"babel-loader": "^9.1.2",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"clean-webpack-plugin": "^4.0.0",
"codecov": "^3.8.3",
"compression-webpack-plugin": "^10.0.0",
Expand Down Expand Up @@ -108,13 +109,15 @@
"prettier": "^2.8.4",
"process": "^0.11.10",
"request": "^2.88.2",
"source-map": "^0.7.4",
"standard-version": "^9.5.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"trash-cli": "^5.0.0",
"tslib": "^2.5.0",
"typedoc": "^0.23.25",
"typescript": "^4.9.5",
"url": "^0.11.4",
"validate-commit-msg": "^2.14.0",
"webpack": "^5.76.1",
"webpack-assets-manifest": "^5.1.0",
Expand Down
17 changes: 11 additions & 6 deletions scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
const { runOnEachFile, browserBuildDir, version } = require('./utils');
const Path = require('path');
const Fs = require('fs').promises;
const AWS = require('aws-sdk');
const { S3Client, PutObjectCommand, S3ServiceException } = require("@aws-sdk/client-s3");
const mime = require('mime-types');
const git = require('git-state');

const s3 = new AWS.S3();
const s3Client = new S3Client({region: process.env.AWS_REGION});
// const DEPLOY_BRANCH = 'master';
const path = './';
const repositoryExists = git.isGitSync(path);
Expand Down Expand Up @@ -42,14 +42,19 @@ const pushOneFileToS3 = (basePath, to, cacheControll = 1) => {
ContentType: figureOutFileMimetype(basePath),
};

return s3.putObject(options, (err) => {
if (err) {
const command = new PutObjectCommand(options);

try {
await s3Client.send(command);
resolve(`File: ${file} has been uploaded to: ${to.bucket}/${uploadKey}`);
} catch (err) {
if (err instanceof S3ServiceException) {
console.error('Upload ERROR:', err);
reject(err);
} else {
resolve(`File: ${file} has been uploaded to: ${to.bucket}/${uploadKey}`);
reject(err);
}
});
}
});
};

Expand Down
17 changes: 8 additions & 9 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const glob = require('glob');
const { glob } = require('glob');
const version = require('../package.json').version;
const path = require('path');

Expand All @@ -9,16 +9,15 @@ const getRootPath = () => {
}

const getFiles = (dir, globOpts = {}) => {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
globOpts.cwd = getRootPath();

glob(dir, globOpts, (err, files) => {
if (err) {
return reject(err);
}

return resolve(files);
})
try {
const files = await glob(dir, globOpts);
resolve(files);
} catch (error) {
reject(error);
}
});
}

Expand Down
15 changes: 15 additions & 0 deletions src/lib/api/upload/uploaders/s3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const testHost = 'https://filestack-test.com';
const mockUploadId = '123132123';
const mockRegion = 'test-region';
const mockedUri = '/sometest';
const mockMetaHash= 'test'
const s3Url = testHost + '/fakes3';

const mockStart = jest.fn().mockName('multipart/start');
Expand Down Expand Up @@ -100,6 +101,7 @@ describe('Api/Upload/Uploaders/S3', () => {
region: mockRegion,
upload_id: mockUploadId,
location_url: testHost,
metahash: mockMetaHash,
});

mockUpload.mockReturnValue({
Expand All @@ -121,6 +123,7 @@ describe('Api/Upload/Uploaders/S3', () => {
mimetype: 'test_mimetype',
status: 'test_status',
upload_tags: { test: 123 },
metahash: mockMetaHash,
});
});

Expand Down Expand Up @@ -224,6 +227,7 @@ describe('Api/Upload/Uploaders/S3', () => {
region: mockRegion,
upload_id: mockUploadId,
location_url: testHost.replace('https://', ''),
metahash: mockMetaHash,
});

const u = new S3Uploader({});
Expand All @@ -245,6 +249,7 @@ describe('Api/Upload/Uploaders/S3', () => {
region: mockRegion,
upload_id: mockUploadId,
location_url: testHost.replace('https://', ''),
metahash: mockMetaHash,
});

const u = new S3Uploader({});
Expand All @@ -264,6 +269,7 @@ describe('Api/Upload/Uploaders/S3', () => {
region: mockRegion,
upload_id: mockUploadId,
location_url: testHost.replace('https://', ''),
metahash: mockMetaHash,
});

interceptorS3.once().reply(200, s3Callback, {});
Expand All @@ -288,6 +294,7 @@ describe('Api/Upload/Uploaders/S3', () => {
upload_id: mockUploadId,
location_region: 'test',
location_url: testHost.replace('https://', ''),
metahash: mockMetaHash,
});

interceptorUpload.reply(200, function(_, data) {
Expand Down Expand Up @@ -495,6 +502,7 @@ describe('Api/Upload/Uploaders/S3', () => {
upload_id: mockUploadId,
location_url: testHost,
upload_type: 'intelligent_ingestion',
metahash: mockMetaHash,
});
});

Expand Down Expand Up @@ -571,6 +579,7 @@ describe('Api/Upload/Uploaders/S3', () => {
},
fii: true,
uri: mockedUri,
metahash: mockMetaHash,
});
});

Expand Down Expand Up @@ -647,6 +656,7 @@ describe('Api/Upload/Uploaders/S3', () => {
},
fii: true,
uri: mockedUri,
metahash: mockMetaHash,
});
});

Expand Down Expand Up @@ -732,6 +742,7 @@ describe('Api/Upload/Uploaders/S3', () => {
upload_id: mockUploadId,
location_url: testHost,
upload_type: 'intelligent_ingestion',
metahash: mockMetaHash,
});

interceptorS3.reply(400, {
Expand Down Expand Up @@ -781,6 +792,7 @@ describe('Api/Upload/Uploaders/S3', () => {
upload_id: mockUploadId,
location_url: testHost,
upload_type: 'intelligent_ingestion',
metahash: mockMetaHash,
});

let networkFail = true;
Expand Down Expand Up @@ -847,6 +859,7 @@ describe('Api/Upload/Uploaders/S3', () => {
region: mockRegion,
upload_id: mockUploadId,
location_url: testHost,
metahash: mockMetaHash,
});

let networkFail = true;
Expand Down Expand Up @@ -948,6 +961,7 @@ describe('Api/Upload/Uploaders/S3', () => {
location: DEFAULT_STORE_LOCATION,
},
uri: mockedUri,
metahash: mockMetaHash,
});

expect(res[0].handle).toEqual('test_handle');
Expand Down Expand Up @@ -1021,6 +1035,7 @@ describe('Api/Upload/Uploaders/S3', () => {
location: DEFAULT_STORE_LOCATION,
},
uri: mockedUri,
metahash: mockMetaHash,
});

expect(res[0].handle).toEqual('test_handle');
Expand Down
4 changes: 3 additions & 1 deletion src/lib/api/upload/uploaders/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface UploadPayload {
upload_id?: number;
location_url?: string;
location_region?: string;
metahash?: string;
}

export class S3Uploader extends UploaderAbstract {
Expand Down Expand Up @@ -213,6 +214,7 @@ export class S3Uploader extends UploaderAbstract {
upload_id: payload.upload_id,
region: payload.region,
alt: payload.file.alt,
metahash: payload.metahash,
};

if (this.uploadMode === UploadMode.INTELLIGENT || (this.uploadMode === UploadMode.FALLBACK && fiiFallback)) {
Expand Down Expand Up @@ -688,7 +690,7 @@ export class S3Uploader extends UploaderAbstract {
return FsRequest.post(
`${this.getUploadUrl(id)}/multipart/complete`,
{
...this.getDefaultFields(id, ['apikey', 'policy', 'signature', 'uri', 'region', 'upload_id', 'fii', 'alt'], true),
...this.getDefaultFields(id, ['apikey', 'policy', 'signature', 'uri', 'region', 'upload_id', 'fii', 'alt', 'metahash'], true),
// method specific keys
filename: payload.file.name,
mimetype: payload.file.type,
Expand Down
21 changes: 18 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs');
const merge = require('lodash.merge');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const WebpackAssetsManifest = require('webpack-assets-manifest');
const { SourceMapConsumer } = require('source-map');
const banner = fs.readFileSync('./LICENSE', 'utf8').replace('{year}', new Date().getFullYear());

const config = {
Expand Down Expand Up @@ -45,12 +46,24 @@ const config = {
maxAssetSize: 255000
},
plugins: [
{
apply: (compiler) => {
compiler.hooks.beforeRun.tap('SourceMapInit', () => {
SourceMapConsumer.initialize({
'lib/mappings.wasm': path.resolve(
path.dirname(require.resolve('source-map')),
'lib',
'mappings.wasm'
)
});
});
}
},
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
process: "process/browser",
Buffer: ['buffer', 'Buffer']
}),
new webpack.BannerPlugin({ banner }),
new webpack.DefinePlugin({
Expand All @@ -69,9 +82,10 @@ const config = {
'process/browser': require.resolve("process/browser"),
zlib: require.resolve("browserify-zlib"),
stream: require.resolve("stream-browserify"),
buffer: require.resolve("buffer"),
buffer: require.resolve("buffer/"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
url: require.resolve("url"),
},
},
};
Expand All @@ -80,6 +94,7 @@ const umd = merge({}, config, {
output: {
library: {
type: 'umd',
name: 'filestack',
},
filename: 'filestack.umd.js',
},
Expand Down