mirror of
https://github.com/scratchfoundation/scratch-storage.git
synced 2025-07-24 13:09:20 -04:00
replace 'got' with 'nets' and fix the 'web+commonjs2' and 'node+commonjs2' targets in webpack.config.js
This commit is contained in:
parent
58f45be54e
commit
6fc4832f97
5 changed files with 32 additions and 26 deletions
|
@ -8,7 +8,7 @@
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/LLK/scratch-storage.git"
|
"url": "https://github.com/LLK/scratch-storage.git"
|
||||||
},
|
},
|
||||||
"main": "./dist/node/scratch-storage.js",
|
"main": "./dist/web_commonjs2/scratch-storage.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "./node_modules/.bin/webpack --progress --colors --bail",
|
"build": "./node_modules/.bin/webpack --progress --colors --bail",
|
||||||
"coverage": "./node_modules/.bin/tap ./test/{unit,integration}/*.js --coverage --coverage-report=lcov",
|
"coverage": "./node_modules/.bin/tap ./test/{unit,integration}/*.js --coverage --coverage-report=lcov",
|
||||||
|
@ -38,6 +38,7 @@
|
||||||
"json": "^9.0.4",
|
"json": "^9.0.4",
|
||||||
"json-loader": "0.5.4",
|
"json-loader": "0.5.4",
|
||||||
"localforage": "1.5.0",
|
"localforage": "1.5.0",
|
||||||
|
"nets": "^3.2.0",
|
||||||
"semantic-release": "^6.3.2",
|
"semantic-release": "^6.3.2",
|
||||||
"tap": "8.0.1",
|
"tap": "8.0.1",
|
||||||
"text-encoding": "0.6.4",
|
"text-encoding": "0.6.4",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const got = require('got');
|
const nets = require('nets');
|
||||||
|
|
||||||
const Asset = require('./Asset');
|
const Asset = require('./Asset');
|
||||||
const Helper = require('./Helper');
|
const Helper = require('./Helper');
|
||||||
|
@ -66,26 +66,17 @@ class WebHelper extends Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (urlFunction) {
|
if (urlFunction) {
|
||||||
const options = {
|
|
||||||
encoding: null // return body as Buffer
|
|
||||||
};
|
|
||||||
const url = urlFunction(asset);
|
const url = urlFunction(asset);
|
||||||
got(url, options).then(
|
|
||||||
response => {
|
nets({ url: url }, function(err, resp, body) {
|
||||||
if (response.status < 200 || response.status >= 300) {
|
// body is a Buffer
|
||||||
if (response.status !== 404) {
|
if (err) {
|
||||||
errors.push({url: url, result: response});
|
|
||||||
}
|
|
||||||
tryNextSource();
|
|
||||||
} else {
|
|
||||||
asset.setData(response.body, dataFormat);
|
|
||||||
fulfill(asset);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error => {
|
|
||||||
errors.push({url: url, result: error});
|
|
||||||
tryNextSource();
|
tryNextSource();
|
||||||
});
|
} else {
|
||||||
|
asset.setData(body, dataFormat);
|
||||||
|
fulfill(asset);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (errors.length > 0) {
|
} else if (errors.length > 0) {
|
||||||
reject(errors);
|
reject(errors);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const test = require('tap').test;
|
const test = require('tap').test;
|
||||||
|
|
||||||
const ScratchStorage = require('../../dist/node/scratch-storage');
|
const ScratchStorage = require('../../dist/node_commonjs2/scratch-storage');
|
||||||
|
|
||||||
var storage;
|
var storage;
|
||||||
test('constructor', t => {
|
test('constructor', t => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const test = require('tap').test;
|
const test = require('tap').test;
|
||||||
|
|
||||||
const ScratchStorage = require('../../dist/node/scratch-storage');
|
const ScratchStorage = require('../../dist/node_commonjs2/scratch-storage');
|
||||||
|
|
||||||
var storage;
|
var storage;
|
||||||
test('constructor', t => {
|
test('constructor', t => {
|
||||||
|
|
|
@ -27,7 +27,7 @@ const base = {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
// Web-compatible
|
// Web + UMD
|
||||||
Object.assign({}, base, {
|
Object.assign({}, base, {
|
||||||
target: 'web',
|
target: 'web',
|
||||||
entry: {
|
entry: {
|
||||||
|
@ -36,11 +36,25 @@ module.exports = [
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: __dirname,
|
path: __dirname,
|
||||||
filename: 'dist/web/[name].js'
|
filename: 'dist/web_umd/[name].js'
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Node-compatible
|
// Web + commonjs2
|
||||||
|
Object.assign({}, base, {
|
||||||
|
target: 'web',
|
||||||
|
entry: {
|
||||||
|
'scratch-storage': './src/index.js'
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
library: 'ScratchStorage',
|
||||||
|
libraryTarget: 'commonjs2',
|
||||||
|
path: __dirname,
|
||||||
|
filename: 'dist/web_commonjs2/[name].js'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Node + commonjs2
|
||||||
Object.assign({}, base, {
|
Object.assign({}, base, {
|
||||||
target: 'node',
|
target: 'node',
|
||||||
entry: {
|
entry: {
|
||||||
|
@ -50,7 +64,7 @@ module.exports = [
|
||||||
library: 'ScratchStorage',
|
library: 'ScratchStorage',
|
||||||
libraryTarget: 'commonjs2',
|
libraryTarget: 'commonjs2',
|
||||||
path: __dirname,
|
path: __dirname,
|
||||||
filename: 'dist/node/[name].js'
|
filename: 'dist/node_commonjs2/[name].js'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue