[Polyfills] Rewrite
This commit is contained in:
parent
9ce5e8c443
commit
6cfa808f7f
6 changed files with 26 additions and 22 deletions
18
.github/workflows/release_nightly.yml
vendored
18
.github/workflows/release_nightly.yml
vendored
|
@ -21,18 +21,12 @@ jobs:
|
||||||
- name: NPM Install
|
- name: NPM Install
|
||||||
run: cd src; npm i; cd ..
|
run: cd src; npm i; cd ..
|
||||||
|
|
||||||
- name: Install Asar
|
- name: Pack
|
||||||
run: npm i -g asar
|
|
||||||
|
|
||||||
- name: Pack Asar
|
|
||||||
run: npx asar pack src openasar.asar
|
|
||||||
|
|
||||||
- name: Make Deps Asar
|
|
||||||
run: |
|
run: |
|
||||||
cd src
|
npm i -g asar
|
||||||
npm install request
|
node injectPolyfills.js
|
||||||
cd ..
|
rm -rf src/package-lock.json src/node_modules/.package-lock.json src/splash/splashScreen.js.self
|
||||||
npx asar pack src openasar-with-deps.asar
|
npx asar pack src openasar.asar
|
||||||
|
|
||||||
- name: GitHub Release
|
- name: GitHub Release
|
||||||
uses: ncipollo/release-action@v1
|
uses: ncipollo/release-action@v1
|
||||||
|
@ -40,7 +34,7 @@ jobs:
|
||||||
tag: "nightly"
|
tag: "nightly"
|
||||||
allowUpdates: true
|
allowUpdates: true
|
||||||
prerelease: true
|
prerelease: true
|
||||||
artifacts: "openasar.asar,openasar-with-deps.asar"
|
artifacts: "openasar.asar"
|
||||||
|
|
||||||
name: "Nightly"
|
name: "Nightly"
|
||||||
|
|
||||||
|
|
16
injectPolyfills.js
Normal file
16
injectPolyfills.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
const { readdirSync, mkdirSync, copyFileSync } = require('fs');
|
||||||
|
const { join } = require('path');
|
||||||
|
|
||||||
|
const polyfillsDir = join(__dirname, 'polyfills');
|
||||||
|
for (const file of readdirSync(polyfillsDir)) {
|
||||||
|
const [ name ] = file.split('.');
|
||||||
|
const jsPath = join(polyfillsDir, file);
|
||||||
|
|
||||||
|
const moduleDir = join(__dirname, 'src', 'node_modules', name);
|
||||||
|
|
||||||
|
try {
|
||||||
|
mkdirSync(moduleDir);
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
copyFileSync(jsPath, join(moduleDir, 'index.js'));
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ const nodeReq = ({ method, url, headers, qs, timeout, body, stream }) => {
|
||||||
const req = https.request(fullUrl, {
|
const req = https.request(fullUrl, {
|
||||||
method,
|
method,
|
||||||
headers,
|
headers,
|
||||||
timeout: timeout != null ? timeout : DEFAULT_REQUEST_TIMEOUT
|
timeout
|
||||||
}, async (res) => {
|
}, async (res) => {
|
||||||
if (res.statusCode === 301 || res.statusCode === 302) { // Redirect, recall function
|
if (res.statusCode === 301 || res.statusCode === 302) { // Redirect, recall function
|
||||||
return resolve(await nodeReq({
|
return resolve(await nodeReq({
|
||||||
|
@ -38,13 +38,13 @@ module.exports = (options, callback) => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
log('Polyfill > Request', options.method, options.url);
|
// log('Polyfill > Request', options.method, options.url);
|
||||||
|
|
||||||
const listener = {};
|
const listener = {};
|
||||||
|
|
||||||
nodeReq(options).then((res) => { // No error handling because yes
|
nodeReq(options).then((res) => { // No error handling because yes
|
||||||
if (callback) callback(undefined, res, res.body);
|
if (callback) callback(undefined, res, res.body);
|
||||||
listener['response'](res);
|
if (listener['response']) listener['response'](res);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
|
@ -4,13 +4,6 @@ global.oaVersion = '0.2';
|
||||||
|
|
||||||
log('Init', 'OpenAsar v' + oaVersion);
|
log('Init', 'OpenAsar v' + oaVersion);
|
||||||
|
|
||||||
const NodeModule = require('module');
|
|
||||||
const { join } = require('path');
|
|
||||||
|
|
||||||
NodeModule.globalPaths.push(join(__dirname, 'polyfills'));
|
|
||||||
|
|
||||||
log('Polyfills', 'Set up polyfills usage');
|
|
||||||
|
|
||||||
const appSettings = require('./appSettings');
|
const appSettings = require('./appSettings');
|
||||||
global.oaConfig = appSettings.getSettings().get('openasar', {});
|
global.oaConfig = appSettings.getSettings().get('openasar', {});
|
||||||
|
|
||||||
|
|
1
test.sh
1
test.sh
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "Packing asar..."
|
echo "Packing asar..."
|
||||||
|
node injectPolyfills.js
|
||||||
asar pack src app.asar # Package asar
|
asar pack src app.asar # Package asar
|
||||||
# asar list app.asar # List asar for debugging / testing
|
# asar list app.asar # List asar for debugging / testing
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue