[MIRROR] Fix a number of build issues (#3716)

* Fix a number of build issues

* Update babel.config.js

* Update package.json

* Update package.json

* Update dreamseeker.js

* Update package.json

* Update webpack.config.js

* Update yarn.lock

* a

* a

Co-authored-by: Aleksej Komarov <stylemistake@gmail.com>
Co-authored-by: Gandalf <jzo123@hotmail.com>
This commit is contained in:
SkyratBot
2021-02-28 16:28:03 +01:00
committed by GitHub
parent 4bad355c11
commit 5ea469fcf0
17 changed files with 4135 additions and 1626 deletions

7
.vscode/tasks.json vendored
View File

@@ -7,8 +7,14 @@
"windows": { "windows": {
"command": ".\\tools\\build\\build.bat" "command": ".\\tools\\build\\build.bat"
}, },
"options": {
"env": {
"DM_EXE": "${config:dreammaker.byondPath}"
}
},
"problemMatcher": [ "problemMatcher": [
"$dreammaker", "$dreammaker",
"$tsc",
"$eslint-stylish" "$eslint-stylish"
], ],
"group": { "group": {
@@ -33,6 +39,7 @@
"command": ".\\tgui\\bin\\tgui.bat" "command": ".\\tgui\\bin\\tgui.bat"
}, },
"problemMatcher": [ "problemMatcher": [
"$tsc",
"$eslint-stylish" "$eslint-stylish"
], ],
"group": "build", "group": "build",

View File

@@ -48,6 +48,10 @@
)) ))
window.send_asset(get_asset_datum(/datum/asset/simple/namespaced/fontawesome)) window.send_asset(get_asset_datum(/datum/asset/simple/namespaced/fontawesome))
window.send_asset(get_asset_datum(/datum/asset/spritesheet/chat)) window.send_asset(get_asset_datum(/datum/asset/spritesheet/chat))
// Preload assets for /datum/tgui_window
var/datum/asset/asset_tgui = get_asset_datum(/datum/asset/simple/tgui)
asset_tgui.send(src.client)
// Other setup
request_telemetry() request_telemetry()
addtimer(CALLBACK(src, .proc/on_initialize_timed_out), 5 SECONDS) addtimer(CALLBACK(src, .proc/on_initialize_timed_out), 5 SECONDS)

View File

@@ -8,7 +8,10 @@ const createBabelConfig = options => {
const { mode, presets = [], plugins = [] } = options; const { mode, presets = [], plugins = [] } = options;
return { return {
presets: [ presets: [
['@babel/preset-env', { [require.resolve('@babel/preset-typescript'), {
allowDeclareFields: true,
}],
[require.resolve('@babel/preset-env'), {
modules: 'commonjs', modules: 'commonjs',
useBuiltIns: 'entry', useBuiltIns: 'entry',
corejs: '3.8', corejs: '3.8',
@@ -19,16 +22,19 @@ const createBabelConfig = options => {
...presets, ...presets,
], ],
plugins: [ plugins: [
'@babel/plugin-transform-jscript', [require.resolve('@babel/plugin-proposal-class-properties'), {
'babel-plugin-inferno', loose: true,
'babel-plugin-transform-remove-console', }],
'common/string.babel-plugin.cjs', require.resolve('@babel/plugin-transform-jscript'),
require.resolve('babel-plugin-inferno'),
require.resolve('babel-plugin-transform-remove-console'),
require.resolve('common/string.babel-plugin.cjs'),
...plugins, ...plugins,
], ],
}; };
}; };
module.exports = (api) => { module.exports = api => {
api.cache(true); api.cache(true);
const mode = process.env.NODE_ENV; const mode = process.env.NODE_ENV;
return createBabelConfig({ mode }); return createBabelConfig({ mode });

View File

@@ -6,27 +6,37 @@
"packages/*" "packages/*"
], ],
"dependencies": { "dependencies": {
"@babel/core": "^7.12.13", "@babel/core": "^7.13.8",
"@babel/eslint-parser": "^7.12.13", "@babel/eslint-parser": "^7.13.8",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-transform-jscript": "^7.12.13", "@babel/plugin-transform-jscript": "^7.12.13",
"@babel/preset-env": "^7.12.13", "@babel/preset-env": "^7.13.8",
"@babel/preset-typescript": "^7.13.0",
"@types/jest": "^26.0.20",
"@types/jsdom": "^16.2.6",
"@types/node": "^14.14.31",
"@typescript-eslint/parser": "^4.15.2",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2", "babel-loader": "^8.2.2",
"babel-plugin-inferno": "^6.1.1", "babel-plugin-inferno": "^6.1.1",
"babel-plugin-transform-remove-console": "^6.9.4", "babel-plugin-transform-remove-console": "^6.9.4",
"common": "workspace:*", "common": "workspace:*",
"css-loader": "^5.0.2", "css-loader": "^5.1.0",
"cssnano": "^4.1.10", "eslint": "^7.20.0",
"eslint": "^7.19.0",
"eslint-plugin-react": "^7.22.0", "eslint-plugin-react": "^7.22.0",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",
"inferno": "^7.4.7", "inferno": "^7.4.8",
"mini-css-extract-plugin": "^1.3.6", "jest": "^26.6.3",
"sass": "^1.32.6", "jest-circus": "^26.6.3",
"jsdom": "^16.4.0",
"mini-css-extract-plugin": "^1.3.9",
"sass": "^1.32.8",
"sass-loader": "^11.0.1", "sass-loader": "^11.0.1",
"style-loader": "^2.0.0", "style-loader": "^2.0.0",
"terser-webpack-plugin": "^5.1.1", "terser-webpack-plugin": "^5.1.1",
"typescript": "^4.1.5",
"url-loader": "^4.1.1", "url-loader": "^4.1.1",
"webpack": "^5.21.2", "webpack": "^5.24.2",
"webpack-bundle-analyzer": "^4.4.0", "webpack-bundle-analyzer": "^4.4.0",
"webpack-cli": "^4.5.0" "webpack-cli": "^4.5.0"
} }

View File

@@ -52,7 +52,7 @@ DreamSeeker.getInstancesByPids = async pids => {
} }
if (pidsToResolve.length > 0) { if (pidsToResolve.length > 0) {
try { try {
const command = 'netstat -ano | findstr LISTENING'; const command = 'netstat -ano | findstr TCP | findstr 0.0.0.0:0';
const { stdout } = await promisify(exec)(command, { const { stdout } = await promisify(exec)(command, {
// Max buffer of 1MB (default is 200KB) // Max buffer of 1MB (default is 200KB)
maxBuffer: 1024 * 1024, maxBuffer: 1024 * 1024,

View File

@@ -8,7 +8,6 @@ import { createLogger } from 'common/logging.js';
import fs from 'fs'; import fs from 'fs';
import os from 'os'; import os from 'os';
import { basename } from 'path'; import { basename } from 'path';
import { promisify } from 'util';
import { resolveGlob, resolvePath } from './util.js'; import { resolveGlob, resolvePath } from './util.js';
import { regQuery } from './winreg.js'; import { regQuery } from './winreg.js';
import { DreamSeeker } from './dreamseeker.js'; import { DreamSeeker } from './dreamseeker.js';
@@ -93,16 +92,22 @@ export const reloadByondCache = async bundleDir => {
for (let cacheDir of cacheDirs) { for (let cacheDir of cacheDirs) {
// Clear garbage // Clear garbage
const garbage = await resolveGlob(cacheDir, './*.+(bundle|chunk|hot-update).*'); const garbage = await resolveGlob(cacheDir, './*.+(bundle|chunk|hot-update).*');
try {
for (let file of garbage) { for (let file of garbage) {
await promisify(fs.unlink)(file); fs.unlink(file);
} }
// Copy assets // Copy assets
for (let asset of assets) { for (let asset of assets) {
const destination = resolvePath(cacheDir, basename(asset)); const destination = resolvePath(cacheDir, basename(asset));
await promisify(fs.copyFile)(asset, destination); fs.copyFile(asset, destination);
} }
logger.log(`copied ${assets.length} files to '${cacheDir}'`); logger.log(`copied ${assets.length} files to '${cacheDir}'`);
} }
catch (err) {
logger.error(`failed copying to '${cacheDir}'`);
logger.error(err);
}
}
// Notify dreamseeker // Notify dreamseeker
const dss = await dssPromise; const dss = await dssPromise;
if (dss.length > 0) { if (dss.length > 0) {

View File

@@ -5,9 +5,9 @@
"dependencies": { "dependencies": {
"common": "workspace:*", "common": "workspace:*",
"dompurify": "^2.2.6", "dompurify": "^2.2.6",
"inferno": "^7.4.7", "inferno": "^7.4.8",
"inferno-vnode-flags": "^7.4.7", "inferno-vnode-flags": "^7.4.8",
"marked": "^2.0.0", "marked": "^2.0.1",
"tgui-dev-server": "workspace:*", "tgui-dev-server": "workspace:*",
"tgui-polyfill": "workspace:*" "tgui-polyfill": "workspace:*"
} }

View File

@@ -49,16 +49,16 @@ module.exports = (env = {}, argv) => {
chunkLoadTimeout: 15000, chunkLoadTimeout: 15000,
}, },
resolve: { resolve: {
extensions: ['.js', '.jsx'], extensions: ['.tsx', '.ts', '.jsx', '.js'],
alias: {}, alias: {},
}, },
module: { module: {
rules: [ rules: [
{ {
test: /\.m?jsx?$/, test: /\.(js|jsx|cjs|mjs|ts|tsx)$/,
use: [ use: [
{ {
loader: 'babel-loader', loader: require.resolve('babel-loader'),
options: createBabelConfig({ mode }), options: createBabelConfig({ mode }),
}, },
], ],
@@ -73,20 +73,20 @@ module.exports = (env = {}, argv) => {
}, },
}, },
{ {
loader: 'css-loader', loader: require.resolve('css-loader'),
options: { options: {
esModule: false, esModule: false,
}, },
}, },
{ {
loader: 'sass-loader', loader: require.resolve('sass-loader'),
}, },
], ],
}, },
{ {
test: /\.(png|jpg|svg)$/, test: /\.(png|jpg|svg)$/,
use: [ use: [
'url-loader', require.resolve('url-loader'),
], ],
}, },
], ],
@@ -105,6 +105,9 @@ module.exports = (env = {}, argv) => {
cache: { cache: {
type: 'filesystem', type: 'filesystem',
cacheLocation: path.resolve(__dirname, `.yarn/webpack/${mode}`), cacheLocation: path.resolve(__dirname, `.yarn/webpack/${mode}`),
buildDependencies: {
config: [__filename],
},
}, },
stats: createStats(true), stats: createStats(true),
plugins: [ plugins: [

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,20 @@ if %errorlevel% == 0 (
echo | set /p printed_str="Using system-wide Node " echo | set /p printed_str="Using system-wide Node "
call node.exe --version call node.exe --version
call node.exe %* call node.exe %*
) else ( exit /b %errorlevel%
call powershell.exe -NoLogo -ExecutionPolicy Bypass -File "%~dp0\node_.ps1" %*
) )
call powershell -NoLogo -ExecutionPolicy Bypass -File "%~dp0\node_.ps1" Download-Node
for /f "tokens=* USEBACKQ" %%s in (`
call powershell -NoLogo -ExecutionPolicy Bypass -File "%~dp0\node_.ps1" Get-Path
`) do (
set "PATH=%%s;%PATH%"
)
where node.exe >nul 2>nul
if %errorlevel% == 0 (
echo | set /p printed_str="Using vendored Node "
call node.exe --version
call node.exe %*
exit /b %errorlevel%
)
echo "build.bat: Failed to bootstrap Node!"
exit /b 1

View File

@@ -1,23 +1,9 @@
## bootstrap/node_.ps1 ## bootstrap/node_.ps1
## ## Downloads a Node version to a cache directory and invokes it.
## Node bootstrapping script for Windows.
##
## Automatically downloads a Node version to a cache directory and invokes it.
##
## The underscore in the name is so that typing `bootstrap/node` into
## PowerShell finds the `.bat` file first, which ensures this script executes
## regardless of ExecutionPolicy.
#Requires -Version 4.0
$Host.ui.RawUI.WindowTitle = "starting :: node $Args"
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
## This forces UTF-8 encoding across all powershell built-ins function Extract-Variable {
$OutputEncoding = [System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
function ExtractVersion {
param([string] $Path, [string] $Key) param([string] $Path, [string] $Key)
foreach ($Line in Get-Content $Path) { foreach ($Line in Get-Content $Path) {
if ($Line.StartsWith("export $Key=")) { if ($Line.StartsWith("export $Key=")) {
@@ -27,31 +13,46 @@ function ExtractVersion {
throw "Couldn't find value for $Key in $Path" throw "Couldn't find value for $Key in $Path"
} }
function Download-Node {
if (Test-Path $NodeTarget -PathType Leaf) {
return
}
Write-Output "Downloading Node v$NodeVersion"
New-Item $NodeTargetDir -ItemType Directory -ErrorAction silentlyContinue | Out-Null
$WebClient = New-Object Net.WebClient
$WebClient.DownloadFile($NodeSource, $NodeTarget)
}
## Convenience variables ## Convenience variables
$BaseDir = Split-Path $script:MyInvocation.MyCommand.Path $BaseDir = Split-Path $script:MyInvocation.MyCommand.Path
$Cache = "$BaseDir/.cache" $Cache = "$BaseDir\.cache"
if ($Env:TG_BOOTSTRAP_CACHE) { if ($Env:TG_BOOTSTRAP_CACHE) {
$Cache = $Env:TG_BOOTSTRAP_CACHE $Cache = $Env:TG_BOOTSTRAP_CACHE
} }
$NodeVersion = ExtractVersion -Path "$BaseDir/../../dependencies.sh" -Key "NODE_VERSION_PRECISE" $NodeVersion = Extract-Variable -Path "$BaseDir\..\..\dependencies.sh" -Key "NODE_VERSION_PRECISE"
$NodeDir = "$Cache/node-v$NodeVersion" $NodeSource = "https://nodejs.org/download/release/v$NodeVersion/win-x86/node.exe"
$NodeExe = "$NodeDir/node.exe" $NodeTargetDir = "$Cache\node-v$NodeVersion"
$NodeTarget = "$NodeTargetDir\node.exe"
## Download and unzip Node ## Just print the path and exit
if (!(Test-Path $NodeExe -PathType Leaf)) { if ($Args.length -eq 1 -and $Args[0] -eq "Get-Path") {
$Host.ui.RawUI.WindowTitle = "Downloading Node $NodeVersion..." Write-Output "$NodeTargetDir"
New-Item $NodeDir -ItemType Directory -ErrorAction silentlyContinue | Out-Null exit 0
Invoke-WebRequest `
"https://nodejs.org/download/release/v$NodeVersion/win-x86/node.exe" `
-OutFile $NodeExe `
-ErrorAction Stop
} }
## Just download node and exit
if ($Args.length -eq 1 -and $Args[0] -eq "Download-Node") {
Download-Node
exit 0
}
## Download node
Download-Node
## Set PATH so that recursive calls find it ## Set PATH so that recursive calls find it
$Env:PATH = "$NodeDir;$ENV:Path" $Env:PATH = "$NodeTargetDir;$ENV:Path"
## Invoke Node with all command-line arguments ## Invoke Node with all command-line arguments
$Host.ui.RawUI.WindowTitle = "node $Args"
$ErrorActionPreference = "Continue" $ErrorActionPreference = "Continue"
& "$NodeExe" @Args & "$NodeTarget" @Args
exit $LastExitCode exit $LastExitCode

View File

@@ -77,6 +77,7 @@ fi
# Use pip to install our requirements # Use pip to install our requirements
if [ ! -f "$PythonDir/requirements.txt" ] || [ "$(b2sum < "$Sdk/requirements.txt")" != "$(b2sum < "$PythonDir/requirements.txt")" ]; then if [ ! -f "$PythonDir/requirements.txt" ] || [ "$(b2sum < "$Sdk/requirements.txt")" != "$(b2sum < "$PythonDir/requirements.txt")" ]; then
echo "Updating dependencies..." echo "Updating dependencies..."
"$PythonExe" -m pip install -U wheel
"$PythonExe" -m pip install -U pip -r "$Sdk/requirements.txt" "$PythonExe" -m pip install -U pip -r "$Sdk/requirements.txt"
cp "$Sdk/requirements.txt" "$PythonDir/requirements.txt" cp "$Sdk/requirements.txt" "$PythonDir/requirements.txt"
echo "---" echo "---"

View File

@@ -6,7 +6,7 @@
*/ */
const { resolve: resolvePath } = require('path'); const { resolve: resolvePath } = require('path');
const { resolveGlob } = require('./cbt/fs'); const { resolveGlob, stat } = require('./cbt/fs');
const { exec } = require('./cbt/process'); const { exec } = require('./cbt/process');
const { Task, runTasks } = require('./cbt/task'); const { Task, runTasks } = require('./cbt/task');
const { regQuery } = require('./cbt/winreg'); const { regQuery } = require('./cbt/winreg');
@@ -16,11 +16,11 @@ process.chdir(resolvePath(__dirname, '../../'));
const taskTgui = new Task('tgui') const taskTgui = new Task('tgui')
.depends('tgui/.yarn/releases/*') .depends('tgui/.yarn/releases/*')
.depends('tgui/.yarn/install-state.gz')
.depends('tgui/yarn.lock') .depends('tgui/yarn.lock')
.depends('tgui/webpack.config.js') .depends('tgui/webpack.config.js')
.depends('tgui/**/package.json') .depends('tgui/**/package.json')
.depends('tgui/packages/**/*.js') .depends('tgui/packages/**/*.+(js|jsx|ts|tsx|cjs|mjs|scss)')
.depends('tgui/packages/**/*.jsx')
.provides('tgui/public/tgui.bundle.css') .provides('tgui/public/tgui.bundle.css')
.provides('tgui/public/tgui.bundle.js') .provides('tgui/public/tgui.bundle.js')
.provides('tgui/public/tgui-common.bundle.js') .provides('tgui/public/tgui-common.bundle.js')
@@ -29,9 +29,9 @@ const taskTgui = new Task('tgui')
.build(async () => { .build(async () => {
// Instead of calling `tgui/bin/tgui`, we reproduce the whole pipeline // Instead of calling `tgui/bin/tgui`, we reproduce the whole pipeline
// here for maximum compilation speed. // here for maximum compilation speed.
const yarnRelease = resolveGlob('./tgui/.yarn/releases/yarn-*.cjs')[0] const yarnPath = resolveGlob('./tgui/.yarn/releases/yarn-*.cjs')[0]
.replace('/tgui/', '/'); .replace('/tgui/', '/');
const yarn = args => exec('node', [yarnRelease, ...args], { const yarn = args => exec('node', [yarnPath, ...args], {
cwd: './tgui', cwd: './tgui',
}); });
await yarn(['install']); await yarn(['install']);
@@ -48,29 +48,54 @@ const taskDm = new Task('dm')
.depends('modular_skyrat/**') // SKYRAT EDIT ADDITION -- check modular_skyrat too pls, build.js .depends('modular_skyrat/**') // SKYRAT EDIT ADDITION -- check modular_skyrat too pls, build.js
.depends('tgui/public/tgui.html') .depends('tgui/public/tgui.html')
.depends('tgui/public/*.bundle.*') .depends('tgui/public/*.bundle.*')
.depends('tgui/public/*.chunk.*')
.depends('tgstation.dme') .depends('tgstation.dme')
.provides('tgstation.dmb') .provides('tgstation.dmb')
.provides('tgstation.rsc') .provides('tgstation.rsc')
.build(async () => { .build(async () => {
let compiler = 'dm'; const dmPath = await (async () => {
// Let's do some registry queries on Windows, because dm is not in PATH. // Search in array of paths
if (process.platform === 'win32') { const paths = [
const installPath = ( ...(process.env.DM_EXE && process.env.DM_EXE.split(',')),
await regQuery( 'C:\\Program Files\\BYOND\\bin\\dm.exe',
'HKLM\\Software\\Dantom\\BYOND', 'C:\\Program Files (x86)\\BYOND\\bin\\dm.exe',
'installpath') ['reg', 'HKLM\\Software\\Dantom\\BYOND', 'installpath'],
|| await regQuery( ['reg', 'HKLM\\SOFTWARE\\WOW6432Node\\Dantom\\BYOND', 'installpath'],
'HKLM\\SOFTWARE\\WOW6432Node\\Dantom\\BYOND', ];
'installpath') const isFile = path => {
try {
const fstat = stat(path);
return fstat && fstat.isFile();
}
catch (err) {}
return false;
};
for (let path of paths) {
// Resolve a registry key
if (Array.isArray(path)) {
const [type, ...args] = path;
path = await regQuery(...args);
}
if (!path) {
continue;
}
// Check if path exists
if (isFile(path)) {
return path;
}
if (isFile(path + '/dm.exe')) {
return path + '/dm.exe';
}
if (isFile(path + '/bin/dm.exe')) {
return path + '/bin/dm.exe';
}
}
// Default paths
return (
process.platform === 'win32' && 'dm.exe'
|| 'DreamMaker'
); );
if (installPath) { })();
compiler = resolvePath(installPath, 'bin/dm.exe'); await exec(dmPath, ['tgstation.dme']);
}
} else {
compiler = 'DreamMaker';
}
await exec(compiler, ['tgstation.dme']);
}); });
// Frontend // Frontend
@@ -79,7 +104,7 @@ const tasksToRun = [
taskDm, taskDm,
]; ];
if (process.env['TG_BUILD_TGS_MODE']) { if (process.env.TG_BUILD_TGS_MODE) {
tasksToRun.pop(); tasksToRun.pop();
} }

View File

@@ -78,13 +78,10 @@ const exec = (executable, args, options) => {
} }
const child = spawn(executable, args, options); const child = spawn(executable, args, options);
children.add(child); children.add(child);
child.stdout.on('data', data => { child.stdout.pipe(process.stdout, { end: false });
process.stdout.write(data); child.stderr.pipe(process.stderr, { end: false });
});
child.stderr.on('data', data => {
process.stderr.write(data);
});
child.stdin.end(); child.stdin.end();
child.on('error', err => reject(err));
child.on('exit', code => { child.on('exit', code => {
children.delete(child); children.delete(child);
if (code !== 0) { if (code !== 0) {
@@ -101,4 +98,5 @@ const exec = (executable, args, options) => {
module.exports = { module.exports = {
exec, exec,
ExitError,
}; };

View File

@@ -5,8 +5,6 @@ tools/deploy.sh ci_test
mkdir ci_test/config mkdir ci_test/config
#test config #test config
cp -r config/* ci_test/config/
mv ci_test/config/config.txt ci_test/config/original_config.txt
cp tools/ci/ci_config.txt ci_test/config/config.txt cp tools/ci/ci_config.txt ci_test/config/config.txt
cd ci_test cd ci_test