diff --git a/.github/workflows/release_nightly.yml b/.github/workflows/release_nightly.yml index 0d45f89..b9520b1 100644 --- a/.github/workflows/release_nightly.yml +++ b/.github/workflows/release_nightly.yml @@ -23,15 +23,9 @@ jobs: with: node-version: 16.x - - name: NPM Install - run: | - cd src - npm i - cd .. - npm i -g asar uglify-js - - name: Pack base asar run: | + npm i -g asar uglify-js node scripts/strip.js node scripts/injectPolyfills.js sed -i -e "s/nightly/nightly-$(git rev-parse HEAD | cut -c 1-7)/" src/index.js diff --git a/polyfills/yauzl.js b/polyfills/yauzl.js new file mode 100644 index 0000000..a0431e8 --- /dev/null +++ b/polyfills/yauzl.js @@ -0,0 +1,47 @@ +// Jank replacement for yauzl by just using unzip where it expects and skipping (speed++, size--) +const { spawn } = require('child_process'); +const { createReadStream, mkdirSync, rmdirSync } = require('original-fs'); +const { join, basename } = require('path'); + +exports.open = async (zipPath, _options, callback) => { + const extractPath = join(global.moduleDataPath, basename(zipPath).split('.')[0].split('-')[0]); + const listeners = []; + log('Yauzl', 'Zip path:', zipPath, 'Extract path:', extractPath); + + const errorOut = (err) => { + listeners.error(err); + }; + + callback(null, { + on: (event, listener) => { + listeners[event] = listener; + }, + + readEntry: () => {}, + openReadStream: () => {}, + close: () => {} + }); + + mkdirSync(extractPath, { recursive: true }); + + // const proc = spawn('tar', ['-v', '-xf', `"${zipPath.replaceAll('"', '')}"`, '-C', `"${extractPath}"`]); + const proc = spawn('unzip', ['-o', `${zipPath.replaceAll('"', '')}`, '-d', `${extractPath}`]); + console.log('spawn'); + proc.stdout.on('data', (data) => { + }); + + proc.stderr.on('data', (data) => { + console.log('stderr', data.toString()); + errorOut(data.toString()); + }); + + proc.on('error', (err) => { + errorOut(err); + }); + + proc.on('close', async () => { + finishedExtract = true; + console.log('close'); + listeners.end(); + }); +}; \ No newline at end of file diff --git a/src/package.json b/src/package.json index a8f3656..aee2c86 100644 --- a/src/package.json +++ b/src/package.json @@ -1,8 +1,5 @@ { "name": "discord", "description": "Open-source alternative of Discord desktop's app.asar", - "main": "index.js", - "dependencies": { - "yauzl": "^2.10.0" - } + "main": "index.js" } \ No newline at end of file