From f3b8251408d348577f177626a1489ca326361011 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Tue, 11 Aug 2020 16:21:14 -0700 Subject: [PATCH] build scratch-gui from source instead of using its build output --- package-deps.json | 1 - package-lock.json | 21 --------------------- package.json | 8 ++------ scripts/npm-in-gui.js | 25 ------------------------- webpack.makeConfig.js | 18 +++++++++--------- webpack.renderer.js | 20 ++++++++++++++++---- 6 files changed, 27 insertions(+), 66 deletions(-) delete mode 100644 scripts/npm-in-gui.js diff --git a/package-deps.json b/package-deps.json index a3af1ca..90ec61e 100644 --- a/package-deps.json +++ b/package-deps.json @@ -18,7 +18,6 @@ "nets": "^3.2.0", "rimraf": "^3.0.2", "scratch-gui": "github:LLK/scratch-gui#scratch-desktop", - "source-map-loader": "^0.2.4", "uuid": "^8.0.0" } } diff --git a/package-lock.json b/package-lock.json index 818a0b8..2d827ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15577,27 +15577,6 @@ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" }, - "source-map-loader": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/source-map-loader/-/source-map-loader-0.2.4.tgz", - "integrity": "sha512-OU6UJUty+i2JDpTItnizPrlpOIBLmQbWMuBg9q5bVtnHACqw1tn9nNwqJLbv0/00JjnJb/Ee5g5WS5vrRv7zIQ==", - "dev": true, - "requires": { - "async": "^2.5.0", - "loader-utils": "^1.1.0" - }, - "dependencies": { - "async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", - "dev": true, - "requires": { - "lodash": "^4.17.14" - } - } - } - }, "source-map-resolve": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.5.3.tgz", diff --git a/package.json b/package.json index 73e1861..8c42063 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,9 @@ "version": "3.13.1", "license": "BSD-3-Clause", "scripts": { - "clean": "rimraf ./dist ./static/assets && node ./scripts/npm-in-gui.js run clean", + "clean": "rimraf ./dist ./static/assets", "start": "electron-webpack dev --bail --display-error-details --env.minify=false", - "compile": "npm run build-gui && electron-webpack --bail --display-error-details --env.minify=false", + "compile": "electron-webpack --bail --display-error-details --env.minify=false", "fetch": "rimraf ./static/assets/ && mkdirp ./static/assets/ && node ./scripts/fetchMediaLibraryAssets.js", "build": "npm run build:dev", "build:dev": "npm run compile && npm run doBuild -- --mode=dev", @@ -19,9 +19,6 @@ "distDev": "npm run clean && npm run compile && npm run fetch && npm run doBuild -- --mode=dev", "test": "npm run test:lint", "test:lint": "eslint --cache --color --ext .jsx,.js .", - "postinstall": "node ./scripts/npm-in-gui.js install", - "build-gui": "node ./scripts/npm-in-gui.js run build", - "watch-gui": "node ./scripts/npm-in-gui.js run watch", "rebuild-deps": "node ./scripts/rebuild-deps.js" }, "repository": { @@ -129,7 +126,6 @@ "scratch-svg-renderer": "0.2.0-prerelease.20200610220938", "scratch-vm": "0.2.0-prerelease.20200720182258", "selenium-webdriver": "3.6.0", - "source-map-loader": "^0.2.4", "startaudiocontext": "1.2.1", "style-loader": "^0.23.0", "svg-to-image": "1.1.3", diff --git a/scripts/npm-in-gui.js b/scripts/npm-in-gui.js deleted file mode 100644 index f879bfd..0000000 --- a/scripts/npm-in-gui.js +++ /dev/null @@ -1,25 +0,0 @@ -const childProcess = require('child_process'); -const path = require('path'); - -// process.argv: ['node', 'run-in-gui.js', 'foo', ...] -const args = process.argv.slice(2); - -// copy environment (including PATH) then add or replace BUILD_MODE and STATIC_PATH -const env = { - ...process.env, - BUILD_MODE: 'dist', - STATIC_PATH: 'static' -}; - -const child = childProcess.spawnSync( - 'npm', args, - { - cwd: path.join('node_modules', 'scratch-gui'), - env, - shell: true, - stdio: 'inherit' - } -); - -if (child.error) throw child.error; -process.exit(child.status); diff --git a/webpack.makeConfig.js b/webpack.makeConfig.js index ced6f32..57b37e6 100644 --- a/webpack.makeConfig.js +++ b/webpack.makeConfig.js @@ -1,4 +1,5 @@ const childProcess = require('child_process'); +const path = require('path'); const electronPath = require('electron'); const webpack = require('webpack'); @@ -49,9 +50,8 @@ const makeConfig = function (defaultConfig, options) { const shouldDisable = options.disableDefaultRulesForExtensions.some( ext => rule.test.test(`test.${ext}`) ); - if (shouldDisable) { - console.log(`${options.name}: Discarding electron-webpack default rule for ${rule.test}`); - } + const statusWord = shouldDisable ? 'Discarding' : 'Keeping'; + console.log(`${options.name}: ${statusWord} electron-webpack default rule for ${rule.test}`); return !shouldDisable; }); } @@ -67,11 +67,6 @@ const makeConfig = function (defaultConfig, options) { loader: 'babel-loader', options: babelOptions }, - { - test: sourceFileTest, - loader: 'source-map-loader', - enforce: 'pre' - }, { // coped from scratch-gui test: /\.css$/, use: [{ @@ -114,7 +109,12 @@ const makeConfig = function (defaultConfig, options) { ].concat(options.plugins || []), resolve: { cacheWithContext: false, - symlinks: false + symlinks: false, + alias: { + // act like scratch-gui has this line in its package.json: + // "browser": "./src/index.js" + 'scratch-gui$': path.resolve(__dirname, 'node_modules', 'scratch-gui', 'src', 'index.js') + } } }); }; diff --git a/webpack.renderer.js b/webpack.renderer.js index c290816..ce92ad9 100644 --- a/webpack.renderer.js +++ b/webpack.renderer.js @@ -10,14 +10,26 @@ module.exports = defaultConfig => { name: 'renderer', useReact: true, - disableDefaultRulesForExtensions: ['js', 'jsx', 'css', 'svg', 'png', 'wav', 'gif', 'jpg'], + disableDefaultRulesForExtensions: ['js', 'jsx', 'css', 'svg', 'png', 'wav', 'gif', 'jpg', 'ttf'], babelPaths: [ - path.resolve(__dirname, 'src', 'renderer') + path.resolve(__dirname, 'src', 'renderer'), + /node_modules[\\/]+scratch-[^\\/]+[\\/]+src/, + /node_modules[\\/]+pify/, + /node_modules[\\/]+@vernier[\\/]+godirect/ ], plugins: [ new CopyWebpackPlugin([{ - from: path.resolve(__dirname, 'node_modules', 'scratch-gui', 'dist', 'static'), - to: 'static' + from: 'node_modules/scratch-blocks/media', + to: 'static/blocks-media' + }]), + new CopyWebpackPlugin([{ + from: 'extension-worker.{js,js.map}', + context: 'node_modules/scratch-vm/dist/web' + }]), + new CopyWebpackPlugin([{ + from: 'src/lib/libraries/*.json', + to: 'static/libraries', + flatten: true }]) ] }