diff --git a/packages/xarc-app-dev/.gitignore b/packages/xarc-app-dev/.gitignore index 065a53e85..52cf89b36 100644 --- a/packages/xarc-app-dev/.gitignore +++ b/packages/xarc-app-dev/.gitignore @@ -505,6 +505,9 @@ sauce_connect*.txt dist tmp .etmp +config +lib +typedef.js ############################################################################### #########################_WALMART_STANDARD_GITIGNORE_########################## diff --git a/packages/xarc-app-dev/package.json b/packages/xarc-app-dev/package.json index 763acedf3..fc6d2eac7 100644 --- a/packages/xarc-app-dev/package.json +++ b/packages/xarc-app-dev/package.json @@ -13,9 +13,13 @@ }, "license": "Apache-2.0", "scripts": { - "test": "clap test", - "coverage": "clap check", - "format": "prettier --write --print-width 100 *.{js,jsx} `find . -type d -d 1 -exec echo '{}/**/*.{js,jsx}' \\; | egrep -v '(/node_modules/|/dist/|/coverage/)'`" + "compile": "tsc", + "build": "xrun -s compile user/moveDist", + "test": "xrun xarc/test-only", + "coverage": "xrun xarc/test-cov", + "format": "prettier --write --print-width 100 *.{js,jsx} `find . -type d -d 1 -exec echo '{}/**/*.{js,jsx}' \\; | egrep -v '(/node_modules/|/dist/|/coverage/)'`", + "prepublishOnly": "xrun [[build, docs], xarc/check]", + "docs": "xrun xarc/docs" }, "files": [ "config", @@ -72,8 +76,10 @@ "nix-clap": "^1.3.12", "nyc": "^15.1.0", "optional-require": "^1.0.2", + "pkg-up": "^3.1.0", "prompts": "^2.3.2", "ps-get": "^1.1.0", + "read-pkg-up": "^7.0.1", "regenerator-runtime": "^0.13.7", "request": "^2.88.2", "require-at": "^1.0.4", @@ -93,12 +99,17 @@ "xsh": "^0.4.5" }, "devDependencies": { + "@istanbuljs/nyc-config-typescript": "^1.0.1", "@types/chai": "^4.2.11", "@types/mocha": "^7.0.2", + "@types/node": "^13.7.6", "@types/sinon": "^9.0.0", "@types/sinon-chai": "^3.2.4", + "@typescript-eslint/eslint-plugin": "^2.21.0", + "@typescript-eslint/parser": "^2.21.0", "@xarc/app": "../xarc-app", - "@xarc/module-dev": "^2.1.0", + "@xarc/module-dev": "^2.2.3", + "@xarc/run": "^1.0.2", "babel-eslint": "^10.1.0", "chai": "^4.2.0", "electrode-archetype-opt-postcss": "../electrode-archetype-opt-postcss", @@ -113,8 +124,13 @@ "nyc": "^15.0.0", "prettier": "^1.14.2", "run-verify": "^1.2.1", + "shx": "^0.3.2", "sinon": "^7.2.6", - "sinon-chai": "^3.3.0" + "sinon-chai": "^3.3.0", + "source-map-support": "^0.5.16", + "ts-node": "^8.6.2", + "typedoc": "^0.17.4", + "typescript": "^3.8.3" }, "engines": { "node": ">= 10", @@ -145,7 +161,9 @@ "dist", "docs", "gulpfile.js", - "test" + "test", + "xrun*.js", + "xrun*.ts" ], "check-coverage": false, "statements": 0, @@ -153,14 +171,32 @@ "functions": 0, "lines": 0, "cache": true, - "extends": [] + "extends": [ + "@istanbuljs/nyc-config-typescript" + ] }, "publishConfig": { "registry": "https://registry.npmjs.org/", "access": "public" }, + "@xarc/module-dev": { + "srcDir": [ + "src", + "test", + "scripts" + ], + "features": [ + "eslint", + "eslintTS", + "mocha", + "typedoc", + "typescript" + ] + }, "mocha": { "require": [ + "ts-node/register", + "source-map-support/register", "@xarc/module-dev/config/test/setup.js" ], "recursive": true diff --git a/packages/xarc-app-dev/scripts/l10n/flatten-messages.js b/packages/xarc-app-dev/scripts/l10n/flatten-messages.js index ed0f7e97b..6596b1442 100644 --- a/packages/xarc-app-dev/scripts/l10n/flatten-messages.js +++ b/packages/xarc-app-dev/scripts/l10n/flatten-messages.js @@ -1,5 +1,7 @@ "use strict"; +/* eslint-disable no-process-exit, no-console */ + const _ = require("lodash"); const Promise = require("bluebird"); const fs = Promise.promisifyAll(require("fs-extra")); diff --git a/packages/xarc-app-dev/scripts/map-isomorphic-cdn.js b/packages/xarc-app-dev/scripts/map-isomorphic-cdn.js index 9e8496c55..429ce4b51 100644 --- a/packages/xarc-app-dev/scripts/map-isomorphic-cdn.js +++ b/packages/xarc-app-dev/scripts/map-isomorphic-cdn.js @@ -1,6 +1,6 @@ "use strict"; -/* eslint-disable max-statements */ +/* eslint-disable max-statements, no-process-exit */ const logger = require("../lib/logger"); const fs = require("fs"); @@ -13,7 +13,7 @@ function exit(code) { function mapIsomorphicCdn(appDir) { appDir = appDir || process.cwd(); - const isoConfigFile = Path.join(appDir, isoConfig.prodConfigFile); + const isoConfigFile = Path.join(appDir, ".isomorphic-loader-config.json"); const cdnAssetsFile = Path.join(appDir, "config/assets.json"); const isoConfig = require(isoConfigFile); const cdnAssets = require(cdnAssetsFile); diff --git a/packages/xarc-app-dev/scripts/merge-isomorphic-assets.js b/packages/xarc-app-dev/scripts/merge-isomorphic-assets.js index 22dea50cf..e35d30d3c 100644 --- a/packages/xarc-app-dev/scripts/merge-isomorphic-assets.js +++ b/packages/xarc-app-dev/scripts/merge-isomorphic-assets.js @@ -1,5 +1,7 @@ "use strict"; +/* eslint-disable no-process-exit */ + const Fs = require("fs"); const filterScanDir = require("filter-scan-dir"); const Path = require("path"); diff --git a/packages/xarc-app-dev/src/config/archetype.ts b/packages/xarc-app-dev/src/config/archetype.ts index 30807ea29..adf27a7b3 100644 --- a/packages/xarc-app-dev/src/config/archetype.ts +++ b/packages/xarc-app-dev/src/config/archetype.ts @@ -1,14 +1,8 @@ -"use strict"; - const Path = require("path"); const { merge } = require("lodash"); -const { getXarcOptions } = require("../lib/utils"); +const { getXarcOptions, getMyPkg } = require("../lib/utils"); const constants = require("./constants"); -const devPkg = require("../package.json"); -const devDir = Path.join(__dirname, ".."); -const devRequire = require(`../require`); -const configDir = Path.join(devDir, "config"); const _ = require("lodash"); const xenvConfig = require("xenv-config"); const makeAppMode = require("@xarc/app/lib/app-mode"); @@ -31,6 +25,10 @@ module.exports = function getDevArchetype(createXarcOptions) { const babel = require("./env-babel")(); const karma = require("./env-karma")(); + const { myPkg: devPkg, myDir: devDir } = getMyPkg(); + const configDir = Path.join(devDir, "config"); + const devRequire = require(Path.join(devDir, "require")); + const config = { ...defaultArchetypeConfig, devDir, diff --git a/packages/xarc-app-dev/src/config/babel/babelrc-client.ts b/packages/xarc-app-dev/src/config/babel/babelrc-client.ts index a2c793ed0..77abf37f2 100644 --- a/packages/xarc-app-dev/src/config/babel/babelrc-client.ts +++ b/packages/xarc-app-dev/src/config/babel/babelrc-client.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, no-console, @typescript-eslint/ban-ts-ignore */ +export {}; const ck = require("chalker"); const requireAt = require("require-at"); @@ -90,6 +91,7 @@ const enableKarmaCov = process.env.ENABLE_KARMA_COV === "true"; const isProduction = (BABEL_ENV || NODE_ENV) === "production"; const isTest = (BABEL_ENV || NODE_ENV) === "test"; +// @ts-ignore const plugins = basePlugins.concat( // test env isTest && ["babel-plugin-dynamic-import-node"], diff --git a/packages/xarc-app-dev/src/config/babel/babelrc-server.ts b/packages/xarc-app-dev/src/config/babel/babelrc-server.ts index db1d3abe0..6b6f33034 100644 --- a/packages/xarc-app-dev/src/config/babel/babelrc-server.ts +++ b/packages/xarc-app-dev/src/config/babel/babelrc-server.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const archetype = require("@xarc/app-dev/config/archetype")(); const optionalRequire = require("optional-require")(require); diff --git a/packages/xarc-app-dev/src/config/babel/babelrc.ts b/packages/xarc-app-dev/src/config/babel/babelrc.ts index 485234c80..7eefcdaa0 100644 --- a/packages/xarc-app-dev/src/config/babel/babelrc.ts +++ b/packages/xarc-app-dev/src/config/babel/babelrc.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, no-console, @typescript-eslint/ban-ts-ignore */ +export {}; /* * A single babel RC for all transpiling, including client and server code. @@ -98,6 +99,7 @@ const basePlugins = [ ] ]; +// @ts-ignore const plugins = basePlugins.concat( // test env isTest && ["babel-plugin-dynamic-import-node"], diff --git a/packages/xarc-app-dev/src/config/dev-proxy.ts b/packages/xarc-app-dev/src/config/dev-proxy.ts index 9e6c84e3c..c2b33a8aa 100644 --- a/packages/xarc-app-dev/src/config/dev-proxy.ts +++ b/packages/xarc-app-dev/src/config/dev-proxy.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const getDevProxy = require("./get-dev-proxy"); diff --git a/packages/xarc-app-dev/src/config/env-app.ts b/packages/xarc-app-dev/src/config/env-app.ts index 14dff22c8..af8a88aea 100644 --- a/packages/xarc-app-dev/src/config/env-app.ts +++ b/packages/xarc-app-dev/src/config/env-app.ts @@ -1,5 +1,8 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + let cachedEnvApp = null; + module.exports = function getAppEnv() { const xenvConfig = require("xenv-config"); const { merge } = require("lodash"); diff --git a/packages/xarc-app-dev/src/config/env-babel.ts b/packages/xarc-app-dev/src/config/env-babel.ts index ef2ca4ce1..27accdc84 100644 --- a/packages/xarc-app-dev/src/config/env-babel.ts +++ b/packages/xarc-app-dev/src/config/env-babel.ts @@ -1,6 +1,9 @@ -"use strict"; -let cachedEnvBabel = null -module.exports = function getEnvBabel () { +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + +let cachedEnvBabel = null; + +module.exports = function getEnvBabel() { const xenvConfig = require("xenv-config"); const { merge } = require("lodash"); @@ -40,5 +43,5 @@ module.exports = function getEnvBabel () { } }; cachedEnvBabel = cachedEnvBabel || xenvConfig(babelConfigSpec, userConfig.babel, { merge }); - return cachedEnvBabel -} + return cachedEnvBabel; +}; diff --git a/packages/xarc-app-dev/src/config/env-karma.ts b/packages/xarc-app-dev/src/config/env-karma.ts index b3af39fca..934fd0652 100644 --- a/packages/xarc-app-dev/src/config/env-karma.ts +++ b/packages/xarc-app-dev/src/config/env-karma.ts @@ -1,5 +1,8 @@ -"use strict"; -let cachedEnvKarma = null +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + +let cachedEnvKarma = null; + module.exports = function getEnvKarma() { const xenvConfig = require("xenv-config"); const { merge } = require("lodash"); @@ -9,5 +12,5 @@ module.exports = function getEnvKarma() { browser: { env: "KARMA_BROWSER", default: "chrome" } }; cachedEnvKarma = cachedEnvKarma || xenvConfig(karmaConfigSpec, userConfig.karma, { merge }); - return cachedEnvKarma -} + return cachedEnvKarma; +}; diff --git a/packages/xarc-app-dev/src/config/env-proxy.ts b/packages/xarc-app-dev/src/config/env-proxy.ts index 76834b22f..726cc64c0 100644 --- a/packages/xarc-app-dev/src/config/env-proxy.ts +++ b/packages/xarc-app-dev/src/config/env-proxy.ts @@ -1,8 +1,11 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + const { merge } = require("lodash"); -let cachedEnvProxy = null -module.exports = function getEnvProxy () { +let cachedEnvProxy = null; + +module.exports = function getEnvProxy() { const xenvConfig = require("xenv-config"); const proxyConfigSpec = { @@ -19,5 +22,5 @@ module.exports = function getEnvProxy () { elevated: { env: ["ELECTRODE_DEV_ELEVATED"], default: false } }; cachedEnvProxy = cachedEnvProxy || xenvConfig(proxyConfigSpec, {}, { merge }); - return cachedEnvProxy -} + return cachedEnvProxy; +}; diff --git a/packages/xarc-app-dev/src/config/env-webpack.ts b/packages/xarc-app-dev/src/config/env-webpack.ts index 6ab9e24f8..a9ed7ed73 100644 --- a/packages/xarc-app-dev/src/config/env-webpack.ts +++ b/packages/xarc-app-dev/src/config/env-webpack.ts @@ -1,7 +1,9 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; -let cachedWebpackConfig = null -module.exports = function getEnvWebpack () { +let cachedWebpackConfig = null; + +module.exports = function getEnvWebpack() { const xenvConfig = require("xenv-config"); const userConfig = require("./user-config")(); const { merge } = require("lodash"); @@ -48,6 +50,7 @@ module.exports = function getEnvWebpack () { loadDlls: { env: "ELECTRODE_LOAD_DLLS", type: "json", default: {} }, minify: { env: "WEBPACK_MINIFY", default: true } }; - cachedWebpackConfig = cachedWebpackConfig || xenvConfig(webpackConfigSpec, userConfig.webpack, { merge }); - return cachedWebpackConfig -} + cachedWebpackConfig = + cachedWebpackConfig || xenvConfig(webpackConfigSpec, userConfig.webpack, { merge }); + return cachedWebpackConfig; +}; diff --git a/packages/xarc-app-dev/src/config/get-dev-proxy.ts b/packages/xarc-app-dev/src/config/get-dev-proxy.ts index 230eed0a1..b6c19604d 100644 --- a/packages/xarc-app-dev/src/config/get-dev-proxy.ts +++ b/packages/xarc-app-dev/src/config/get-dev-proxy.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, max-statements, no-console, prefer-const */ +export {}; const Path = require("path"); const Fs = require("fs"); diff --git a/packages/xarc-app-dev/src/config/jest/__mocks__/file-mock.ts b/packages/xarc-app-dev/src/config/jest/__mocks__/file-mock.ts index ea1367c1e..4f87cb004 100644 --- a/packages/xarc-app-dev/src/config/jest/__mocks__/file-mock.ts +++ b/packages/xarc-app-dev/src/config/jest/__mocks__/file-mock.ts @@ -1,3 +1,6 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + // __mocks__/fileMock.js module.exports = "test-file-stub"; diff --git a/packages/xarc-app-dev/src/config/jest/__mocks__/framework-mock.ts b/packages/xarc-app-dev/src/config/jest/__mocks__/framework-mock.ts index 1c5576a08..a4cfd6689 100644 --- a/packages/xarc-app-dev/src/config/jest/__mocks__/framework-mock.ts +++ b/packages/xarc-app-dev/src/config/jest/__mocks__/framework-mock.ts @@ -1,4 +1,6 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + const optionalRequire = require("optional-require")(require); const Enzyme = optionalRequire("enzyme"); diff --git a/packages/xarc-app-dev/src/config/jest/jest.config.ts b/packages/xarc-app-dev/src/config/jest/jest.config.ts index bb3e17a2a..1809f363e 100644 --- a/packages/xarc-app-dev/src/config/jest/jest.config.ts +++ b/packages/xarc-app-dev/src/config/jest/jest.config.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const Path = require("path"); const _ = require("lodash"); diff --git a/packages/xarc-app-dev/src/config/karma/browser-settings.ts b/packages/xarc-app-dev/src/config/karma/browser-settings.ts index 38255fd36..32b087bcd 100644 --- a/packages/xarc-app-dev/src/config/karma/browser-settings.ts +++ b/packages/xarc-app-dev/src/config/karma/browser-settings.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, no-process-exit */ +export {}; module.exports = function(settings) { const archetype = require("@xarc/app/config/archetype")(); diff --git a/packages/xarc-app-dev/src/config/karma/karma.conf.coverage.ts b/packages/xarc-app-dev/src/config/karma/karma.conf.coverage.ts index 84fbb3afd..de9bf7a46 100644 --- a/packages/xarc-app-dev/src/config/karma/karma.conf.coverage.ts +++ b/packages/xarc-app-dev/src/config/karma/karma.conf.coverage.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; process.env.KARMA_RUN_TYPE = "coverage"; diff --git a/packages/xarc-app-dev/src/config/karma/karma.conf.dev.ts b/packages/xarc-app-dev/src/config/karma/karma.conf.dev.ts index deebca71d..e3827b85d 100644 --- a/packages/xarc-app-dev/src/config/karma/karma.conf.dev.ts +++ b/packages/xarc-app-dev/src/config/karma/karma.conf.dev.ts @@ -1,4 +1,6 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + /* * Karma Configuration: "dev" version. * diff --git a/packages/xarc-app-dev/src/config/karma/karma.conf.ts b/packages/xarc-app-dev/src/config/karma/karma.conf.ts index 0c8892e63..ac60e0ea8 100644 --- a/packages/xarc-app-dev/src/config/karma/karma.conf.ts +++ b/packages/xarc-app-dev/src/config/karma/karma.conf.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, no-console */ +export {}; const Path = require("path"); const customCheck = require("@xarc/webpack/lib/util/custom-check"); diff --git a/packages/xarc-app-dev/src/config/karma/karma.conf.watch.ts b/packages/xarc-app-dev/src/config/karma/karma.conf.watch.ts index ac13da567..cbf22fa04 100644 --- a/packages/xarc-app-dev/src/config/karma/karma.conf.watch.ts +++ b/packages/xarc-app-dev/src/config/karma/karma.conf.watch.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/ban-ts-ignore */ +export {}; /* * Karma Configuration: "watch" version. @@ -19,6 +20,7 @@ module.exports = function(config) { "http://127.0.0.1:3001/assets/bundle.js" // Watch these files but do not add them to the bundle. ].concat( + // @ts-ignore ["src/client/**", "test/**"].map(pattern => { return { pattern, diff --git a/packages/xarc-app-dev/src/config/karma/util/load-electrode-dll.ts b/packages/xarc-app-dev/src/config/karma/util/load-electrode-dll.ts index 479cca075..e06b93c43 100644 --- a/packages/xarc-app-dev/src/config/karma/util/load-electrode-dll.ts +++ b/packages/xarc-app-dev/src/config/karma/util/load-electrode-dll.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const dllUtil = require("@xarc/webpack/lib/util/dll-util"); diff --git a/packages/xarc-app-dev/src/config/karma/util/load-user-config.ts b/packages/xarc-app-dev/src/config/karma/util/load-user-config.ts index 4f90776c7..5746e1a0f 100644 --- a/packages/xarc-app-dev/src/config/karma/util/load-user-config.ts +++ b/packages/xarc-app-dev/src/config/karma/util/load-user-config.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const optionalRequire = require("optional-require")(require); const Path = require("path"); diff --git a/packages/xarc-app-dev/src/config/load-dev.ts b/packages/xarc-app-dev/src/config/load-dev.ts index 0dd9c8919..8a7a9d977 100644 --- a/packages/xarc-app-dev/src/config/load-dev.ts +++ b/packages/xarc-app-dev/src/config/load-dev.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; // // Load options from the dev archetype diff --git a/packages/xarc-app-dev/src/config/mocha/setup.ts b/packages/xarc-app-dev/src/config/mocha/setup.ts index fde8ad2dd..a3b4e0d4f 100644 --- a/packages/xarc-app-dev/src/config/mocha/setup.ts +++ b/packages/xarc-app-dev/src/config/mocha/setup.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/ban-ts-ignore */ +export {}; const optionalRequire = require("optional-require")(require); const Enzyme = optionalRequire("enzyme"); @@ -24,5 +25,6 @@ if (chai) { chai.config.includeStack = true; + // @ts-ignore global.expect = chai.expect; } diff --git a/packages/xarc-app-dev/src/config/options.ts b/packages/xarc-app-dev/src/config/options.ts index 25d51bdea..aa25aa317 100644 --- a/packages/xarc-app-dev/src/config/options.ts +++ b/packages/xarc-app-dev/src/config/options.ts @@ -1,13 +1,13 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const Path = require("path"); -const pkg = require("../package.json"); const optionalRequire = require("optional-require")(require); const constants = require("./constants"); const utils = require("../lib/utils"); require("../typedef"); -function checkOptArchetypeInAppDep(dependencies, isDev) { +function checkOptArchetypeInAppDep(dependencies, isDev = undefined) { const options = dependencies .filter(x => x.startsWith("electrode-archetype-opt-")) .reduce((acc, name) => { @@ -74,6 +74,8 @@ function getDefaultArchetypeOptions(createXarcOptions) { ...createXarcOptions.electrodePackagesDev ]; + const { myPkg: pkg } = utils.getMyPkg(); + return { dir: Path.resolve(__dirname, ".."), pkg, diff --git a/packages/xarc-app-dev/src/config/user-config.ts b/packages/xarc-app-dev/src/config/user-config.ts index 126482ce0..f31aecb56 100644 --- a/packages/xarc-app-dev/src/config/user-config.ts +++ b/packages/xarc-app-dev/src/config/user-config.ts @@ -1,11 +1,13 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const Path = require("path"); -const { merge } = require("lodash") +const { merge } = require("lodash"); const optionalRequire = require("optional-require")(require); -let cachedUserConfig = null -module.exports = function getUserConfig () { - cachedUserConfig = cachedUserConfig || merge({ options: {} }, optionalRequire(Path.resolve("archetype/config"))); - return cachedUserConfig -} +let cachedUserConfig = null; +module.exports = function getUserConfig() { + cachedUserConfig = + cachedUserConfig || merge({ options: {} }, optionalRequire(Path.resolve("archetype/config"))); + return cachedUserConfig; +}; diff --git a/packages/xarc-app-dev/src/lib/app-dev-middleware.ts b/packages/xarc-app-dev/src/lib/app-dev-middleware.ts index a3de75c2c..b3ba7d1b6 100644 --- a/packages/xarc-app-dev/src/lib/app-dev-middleware.ts +++ b/packages/xarc-app-dev/src/lib/app-dev-middleware.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-magic-numbers, max-statements */ @@ -8,6 +9,8 @@ const isomorphicExtendRequire = require("isomorphic-loader/lib/extend-require"); const { refreshAllSubApps } = require("subapp-util"); class AppDevMiddleware { + webpackDev: any; + constructor() { this.webpackDev = { valid: false, hasErrors: false, hasWarnings: false }; } diff --git a/packages/xarc-app-dev/src/lib/babel-run.ts b/packages/xarc-app-dev/src/lib/babel-run.ts index 645f1ab82..2aedb8225 100644 --- a/packages/xarc-app-dev/src/lib/babel-run.ts +++ b/packages/xarc-app-dev/src/lib/babel-run.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* * Start user's app server from src/server directory in dev mode. diff --git a/packages/xarc-app-dev/src/lib/dev-admin/admin-server.ts b/packages/xarc-app-dev/src/lib/dev-admin/admin-server.ts index f34752aec..48ca3e4a3 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/admin-server.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/admin-server.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable complexity, no-unused-expressions */ /* eslint-disable no-magic-numbers, max-len, max-statements, prefer-template */ @@ -51,6 +52,28 @@ const SERVER_ENVS = { }; class AdminServer { + _opts: any; + _passThru: any; + _messageId: any; + _saveWebpackReportData: any; + _webpackDevRelay: any; + _servers: any; + _io: any; + _shutdown: any; + _fullAppLogUrl: any; + _startTime: any; + _wds: any; + _proxy: any; + _app: any; + _appLogLevel: any; + _menu: any; + _fullyStarted: any; + _ctrlCExit: any; + _statusLine: any; + _hideMenuTimer: any; + _appWatcher: any; + _startDefer: any; + constructor(args, options) { this._opts = args.opts; this._passThru = args._; @@ -109,7 +132,7 @@ class AdminServer { this._io.show(ck`${msg} was ${elapsed} seconds`); } - updateStatus(line) { + updateStatus(line = undefined) { if (line !== undefined) { this._statusLine = line; } @@ -143,7 +166,7 @@ ${proxyItem}M - Show this menu Q - Shutdown this._menu = "\n" + boxen(menu, { margin: { left: 5 }, padding: { right: 3, left: 3 } }); } - showMenu(force) { + showMenu(force = undefined) { const show = force !== undefined ? force : !this._menu; if (show) { @@ -321,7 +344,7 @@ ${proxyItem}M - Show this menu Q - Shutdown } const start = () => { - const forkOpts = { + const forkOpts: any = { env: Object.assign({}, process.env, { ELECTRODE_ADMIN_SERVER: true, ...SERVER_ENVS[name] @@ -360,7 +383,7 @@ ${proxyItem}M - Show this menu Q - Shutdown // // start webpack dev server // - async startWebpackDevServer(debug) { + async startWebpackDevServer(debug = undefined) { const progSig = ` [webpack.Progress] `; const waitStart = async info => { const cwdRegex = new RegExp(process.cwd(), "g"); @@ -562,9 +585,9 @@ ${instruction}` }); } - async startAppServer(debug) { + async startAppServer(debug = undefined) { const skipWatch = debug === "--inspect-brk"; - const logSaver = { + const logSaver: any = { tag: this._app, store: [], fullLogUrl: this._fullAppLogUrl, @@ -619,7 +642,7 @@ ${instruction}` return reader; } - async startProxyServer(debug) { + async startProxyServer(debug = undefined) { await this.startServer({ name: PROXY_SERVER_NAME, killKey: "O", @@ -644,7 +667,7 @@ ${instruction}` const processPending = () => { if (pendingMessages.length > 0) { messageHandler(pendingMessages.shift()); - setTimeout(processPending); + setTimeout(processPending, 10); } }; @@ -666,7 +689,7 @@ ${info.name} - assuming it started.`); started = true; clearTimeout(startTimeout); - setTimeout(processPending); + setTimeout(processPending, 10); return started; }; diff --git a/packages/xarc-app-dev/src/lib/dev-admin/automation-io.ts b/packages/xarc-app-dev/src/lib/dev-admin/automation-io.ts index 2fd2e25bc..f0b6fb660 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/automation-io.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/automation-io.ts @@ -1,4 +1,6 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-empty-function */ +/* eslint-disable @typescript-eslint/ban-ts-ignore */ +export {}; /* eslint-disable no-console, no-process-exit */ diff --git a/packages/xarc-app-dev/src/lib/dev-admin/cdn-mock.ts b/packages/xarc-app-dev/src/lib/dev-admin/cdn-mock.ts index b66b012ef..9049bd229 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/cdn-mock.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/cdn-mock.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-magic-numbers, prefer-template */ diff --git a/packages/xarc-app-dev/src/lib/dev-admin/cleanup.ts b/packages/xarc-app-dev/src/lib/dev-admin/cleanup.ts index bed844ca0..bd037be12 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/cleanup.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/cleanup.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-process-exit */ const { psChildren } = require("ps-get"); @@ -28,15 +29,15 @@ const doCleanup = async () => { }); }; -["uncaughtException", "unhandledRejection"].forEach(event => { - process.on(event, async err => { +["uncaughtException", "unhandledRejection"].forEach((event: any) => { + process.on(event, async (err: Error) => { console.log("dev-admin failure", event, err.stack); await doCleanup(); process.exit(process.exitCode); }); }); -["SIGTERM", "SIGINT", "SIGHUP"].forEach(sig => { +["SIGTERM", "SIGINT", "SIGHUP"].forEach((sig: any) => { process.on(sig, async name => { console.log("dev-admin received signal:", name); await doCleanup(); diff --git a/packages/xarc-app-dev/src/lib/dev-admin/console-io.ts b/packages/xarc-app-dev/src/lib/dev-admin/console-io.ts index 50967339a..f0b95eefc 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/console-io.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/console-io.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-process-exit */ diff --git a/packages/xarc-app-dev/src/lib/dev-admin/dev-express.ts b/packages/xarc-app-dev/src/lib/dev-admin/dev-express.ts index 4fabc8d47..6be6c52a6 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/dev-express.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/dev-express.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-magic-numbers */ diff --git a/packages/xarc-app-dev/src/lib/dev-admin/dev-fastify.ts b/packages/xarc-app-dev/src/lib/dev-admin/dev-fastify.ts index 67440ec44..4438804e9 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/dev-fastify.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/dev-fastify.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-empty-function */ +export {}; /* eslint-disable no-console, no-magic-numbers */ diff --git a/packages/xarc-app-dev/src/lib/dev-admin/dev-hapi.ts b/packages/xarc-app-dev/src/lib/dev-admin/dev-hapi.ts index 2177dce41..c6fd9352a 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/dev-hapi.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/dev-hapi.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-magic-numbers */ diff --git a/packages/xarc-app-dev/src/lib/dev-admin/dev-hapi17.ts b/packages/xarc-app-dev/src/lib/dev-admin/dev-hapi17.ts index 063fb4c9c..298d64e81 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/dev-hapi17.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/dev-hapi17.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-magic-numbers */ @@ -26,7 +27,10 @@ function register(server) { type: "onRequest", method: (request, h) => { if (request.path === "/favicon.ico") { - return h.response("").code(404).takeover(); + return h + .response("") + .code(404) + .takeover(); } const { req } = request.raw; diff --git a/packages/xarc-app-dev/src/lib/dev-admin/dev-koa.ts b/packages/xarc-app-dev/src/lib/dev-admin/dev-koa.ts index 3d4140c19..b43b20381 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/dev-koa.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/dev-koa.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-magic-numbers */ diff --git a/packages/xarc-app-dev/src/lib/dev-admin/dev-server.ts b/packages/xarc-app-dev/src/lib/dev-admin/dev-server.ts index 8184eed96..d64bb518f 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/dev-server.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/dev-server.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable global-require, no-console */ @@ -16,7 +17,7 @@ const express = optionalRequire("express"); // also set by @xarc/app/arch-clap.js // if (process.env.WEBPACK_DEV === undefined) { - process.env.WEBPACK_DEV = true; + process.env.WEBPACK_DEV = "true"; } if (fastifyServer) { diff --git a/packages/xarc-app-dev/src/lib/dev-admin/index.ts b/packages/xarc-app-dev/src/lib/dev-admin/index.ts index 19ccf05cf..1453216e5 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/index.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/index.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const NixClap = require("nix-clap"); diff --git a/packages/xarc-app-dev/src/lib/dev-admin/log-parser.ts b/packages/xarc-app-dev/src/lib/dev-admin/log-parser.ts index 26c93df0b..85f489dae 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/log-parser.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/log-parser.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable max-statements, complexity */ diff --git a/packages/xarc-app-dev/src/lib/dev-admin/log-reader.ts b/packages/xarc-app-dev/src/lib/dev-admin/log-reader.ts index 4616b1fe8..ea7e79c65 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/log-reader.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/log-reader.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const AnsiConvert = require("ansi-to-html"); const ck = require("chalker"); @@ -81,7 +82,7 @@ function getLogEventAsHtml(event) { // eslint-disable-next-line no-console async function displayLogs(maxLevel = DefaultMaxLevel, show = console.log) { - await getLogsByLine(maxLevel, event => show(getLogEventAsAnsi(event, show))); + await getLogsByLine(maxLevel, event => show(getLogEventAsAnsi(event))); } module.exports = { diff --git a/packages/xarc-app-dev/src/lib/dev-admin/middleware.ts b/packages/xarc-app-dev/src/lib/dev-admin/middleware.ts index 5aa46d9b9..00bd62055 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/middleware.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/middleware.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-magic-numbers, max-statements */ /* eslint-disable max-params, prefer-template, complexity, global-require */ @@ -33,10 +34,10 @@ const statsMapper = require("../stats-mapper"); const xsh = require("xsh"); const shell = xsh.$; -function urlJoin() { - if (arguments.length < 1) return undefined; +function urlJoin(...args) { + if (args.length < 1) return undefined; - const base = arguments[0]; + const base = args[0]; if (!base) return undefined; @@ -44,11 +45,11 @@ function urlJoin() { let saved = ""; if (ix > 0) { - arguments[0] = base.substr(ix + 3); + args[0] = base.substr(ix + 3); saved = base.substring(0, ix + 3); } - return saved + Path.posix.join.apply(null, arguments); + return saved + Path.posix.join(...args); } // @@ -69,6 +70,29 @@ const skipWebpackDevMiddleware = req => { ); }; class Middleware { + _options: any; + canContinue: symbol; + _instanceId: number; + _hmrPath: string; + _webpackHotOptions: any; + devMiddleware: any; + hotMiddleware: any; + listAssetPath: string; + publicPath: string; + memFsCwd: string; + cwdMemIndex: any; + cwdIndex: any; + devBaseUrl: string; + devBaseUrlSlash: string; + cwdBaseUrl: string; + cwdContextBaseUrl: string; + reporterUrl: string; + logUrl: string; + logEventsUrl: string; + dllDevUrl: string; + webpackDev: any; + returnReporter: any; + constructor(options) { this._options = options; this.canContinue = Symbol("webpack dev middleware continue"); @@ -295,11 +319,17 @@ doReload(1); `) ); } - const serveStatic = (baseUrl, fileSystem, _serveIndex, cwd, isMemFs) => { + const serveStatic = ( + baseUrl, + fileSystem, + _serveIndex, + cwd = process.cwd(), + isMemFs = false + ) => { req.originalUrl = req.url; // this is what express saves to, else serve-index nukes req.url = req.url.substr(baseUrl.length) || "/"; const PathLib = isMemFs ? Path.posix : Path; - const fullPath = PathLib.join(cwd || process.cwd(), req.url); + const fullPath = PathLib.join(cwd, req.url); return new Promise((resolve, reject) => { fileSystem.stat(fullPath, (err, stats) => { diff --git a/packages/xarc-app-dev/src/lib/dev-admin/redbird-proxy.ts b/packages/xarc-app-dev/src/lib/dev-admin/redbird-proxy.ts index 98db3f50b..eed42c83f 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/redbird-proxy.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/redbird-proxy.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/ban-ts-ignore */ +export {}; /* eslint-disable max-statements, no-process-exit, global-require, no-console */ @@ -141,10 +142,13 @@ const registerElectrodeDevRules = ({ // repeat all rules for 127.0.0.1 appForwards.map(([src, target, opts]) => { return [ + // @ts-ignore formUrl({ protocol, port, ...src, host: src.host || "127.0.0.1" }), formUrl({ ...target, + // @ts-ignore protocol: target.protocol || "http", + // @ts-ignore host: target.host || "127.0.0.1" }), opts @@ -203,7 +207,7 @@ const registerElectrodeDevRules = ({ } }; -const startProxy = inOptions => { +const startProxy = (inOptions = {}) => { APP_RULES = []; const options = Object.assign( { @@ -279,6 +283,7 @@ const startProxy = inOptions => { // if primary protocol is https, then register regular http rules at httpPort if (ssl) { + // @ts-ignore registerElectrodeDevRules({ proxy, protocol: "http", diff --git a/packages/xarc-app-dev/src/lib/dev-admin/redbird-spawn.ts b/packages/xarc-app-dev/src/lib/dev-admin/redbird-spawn.ts index cd7187a0b..6f44f4344 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/redbird-spawn.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/redbird-spawn.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-empty-function */ +export {}; /* eslint-disable no-magic-numbers, no-process-exit, global-require, no-console, max-statements */ @@ -10,7 +11,7 @@ const { controlPaths, settings, httpDevServer } = require("../../config/dev-prox const proxyJs = require.resolve("./redbird-proxy"); const { formUrl } = require("../utils"); -const canListenPort = async (port, host) => { +const canListenPort = async (port, host = undefined) => { const server = http.createServer(() => {}); try { diff --git a/packages/xarc-app-dev/src/lib/dev-admin/webpack-dev-relay.ts b/packages/xarc-app-dev/src/lib/dev-admin/webpack-dev-relay.ts index adebda3b4..92846bfc9 100644 --- a/packages/xarc-app-dev/src/lib/dev-admin/webpack-dev-relay.ts +++ b/packages/xarc-app-dev/src/lib/dev-admin/webpack-dev-relay.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-empty-function */ +export {}; // // relay message between the webpack dev server and app server in dev mode // @@ -17,6 +18,9 @@ const WEBPACK_DEV_MESSAGES = [ ]; class WebpackDevRelay { + _webpackData: any; + _servers: any; + constructor() { this._webpackData = {}; this._servers = {}; @@ -48,9 +52,9 @@ class WebpackDevRelay { } } - receiveAppServerMessage() {} + receiveAppServerMessage(data) {} - _setServer(name, child, handlers) { + _setServer(name, child, handlers = undefined) { const info = this._servers[name]; if (info) { for (const event in info.handlers) { diff --git a/packages/xarc-app-dev/src/lib/fake-res.ts b/packages/xarc-app-dev/src/lib/fake-res.ts index 2cfcaad07..a562eff9c 100644 --- a/packages/xarc-app-dev/src/lib/fake-res.ts +++ b/packages/xarc-app-dev/src/lib/fake-res.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; // // simulate a res object for webpack dev middleware in case diff --git a/packages/xarc-app-dev/src/lib/features.ts b/packages/xarc-app-dev/src/lib/features.ts index 828d5dc2d..57d5b4f60 100644 --- a/packages/xarc-app-dev/src/lib/features.ts +++ b/packages/xarc-app-dev/src/lib/features.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, no-loop-func */ +export {}; const cwd = process.env.PWD || process.cwd(); const optionalRequire = require("optional-require")(require); @@ -42,12 +43,12 @@ const optionalDependenciesList = [ "electrode-archetype-opt-typescript" ]; -const write = function() { - console.log.apply(undefined, arguments); // eslint-disable-line no-console +const write = function(...args) { + console.log(...args); // eslint-disable-line no-console }; -const writeError = function() { - console.error.apply(undefined, arguments); // eslint-disable-line no-console +const writeError = function(...args) { + console.error(...args); // eslint-disable-line no-console }; const Hour = 1000 * 60 * 60; // eslint-disable-line no-magic-numbers @@ -88,6 +89,13 @@ function areCurrentEnablementsLegacy(features) { } class Feature { + packageName: any; + npmDescription: any; + npmElectrodeOptArchetype: any; + npmVersion: any; + _package: any; + _enabled: any; + constructor(packageName) { this.packageName = packageName; this.attachNpmAttributes = this.attachNpmAttributes.bind(this); @@ -314,7 +322,8 @@ class Feature { async function getFeatures() { const features = optionalDependenciesList.map(packageName => new Feature(packageName)); await Promise.all(features.map(feature => feature.attachNpmAttributes())); - features.sort(function(a, b) { // eslint-disable-line prefer-arrow-callback + features.sort(function(a, b) { + // eslint-disable-line prefer-arrow-callback return a.name.localeCompare(b.name); }); return features; @@ -322,7 +331,8 @@ async function getFeatures() { function displayFeatureStatus(features) { const namePadding = - features.reduce(function(a, b) { // eslint-disable-line prefer-arrow-callback + features.reduce(function(a, b) { + // eslint-disable-line prefer-arrow-callback return a.name.length > b.name.length ? a : b; }).name.length + 1; const enabledPadding = 4; @@ -362,10 +372,12 @@ function displayFeatureIssues(features) { features.forEach(feature => { if (!feature.package && feature.enabled) { writeError( - chalk.red([ - `The feature "${feature.packageName}" is enabled but isn’t available`, - `in your node_modules directory. Please perform an "npm install"` - ].join(" ")) + chalk.red( + [ + `The feature "${feature.packageName}" is enabled but isn’t available`, + `in your node_modules directory. Please perform an "npm install"` + ].join(" ") + ) ); } @@ -452,7 +464,8 @@ async function promptForEnabled(features) { feature.enabled = enabled; }); - conflictingFeature = features.find(feature => { // eslint-disable-line + conflictingFeature = features.find(feature => { + // eslint-disable-line // eslint-disable-line no-loop-func const conflicts = feature.getConflictingFeatures(features); if (conflicts.length > 0) { diff --git a/packages/xarc-app-dev/src/lib/load-xrun-tasks.ts b/packages/xarc-app-dev/src/lib/load-xrun-tasks.ts index 345c10c20..ca81129f0 100644 --- a/packages/xarc-app-dev/src/lib/load-xrun-tasks.ts +++ b/packages/xarc-app-dev/src/lib/load-xrun-tasks.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable object-shorthand, max-statements, no-magic-numbers */ /* eslint-disable no-console, no-process-exit, global-require, no-param-reassign */ @@ -111,7 +112,7 @@ module.exports = function loadArchetype(xclap, userXarcOptions) { // If the APP_SERVER_PORT is set to the empty string however, // leave it empty and therefore disable the dev proxy server. if (!process.env.APP_SERVER_PORT && process.env.APP_SERVER_PORT !== "") { - process.env.APP_SERVER_PORT = 3100; + process.env.APP_SERVER_PORT = "3100"; } function quote(str) { @@ -314,13 +315,13 @@ module.exports = function loadArchetype(xclap, userXarcOptions) { }); } - function startAppServer(options) { - options = options || []; - const x = options.length > 0 ? ` with options: ${options.join(" ")}` : ""; + function startAppServer(argFlags = []) { + argFlags = argFlags || []; + const x = argFlags.length > 0 ? ` with options: ${argFlags.join(" ")}` : ""; logger.info(`Starting app server${x}`); logger.info("To terminate press Ctrl+C."); archetype.AppMode.setEnv(archetype.AppMode.lib.dir); - return exec(`node`, options, Path.join(archetype.AppMode.lib.server, "index.js")); + return exec(`node`, argFlags, Path.join(archetype.AppMode.lib.server, "index.js")); } function generateBrowsersListRc() { @@ -362,7 +363,7 @@ module.exports = function loadArchetype(xclap, userXarcOptions) { process.env.ENABLE_CSS_MODULE = "false"; process.env.ENABLE_KARMA_COV = "false"; - const checkFrontendCov = minimum => { + const checkFrontendCov = (minimum = "5") => { if (typeof minimum !== "string") { minimum = "5"; } @@ -1172,7 +1173,7 @@ module.exports = function loadArchetype(xclap, userXarcOptions) { }, ".jest.test-frontend-cov"() { const testDir = jestTestDirectories.find(x => shell.test("-d", x)); - let runJest = testDir; + let runJest: any = testDir; if (!runJest) { const scanned = scanDir.sync({ dir: Path.resolve(AppMode.src.dir), diff --git a/packages/xarc-app-dev/src/lib/logger.ts b/packages/xarc-app-dev/src/lib/logger.ts index 06d6e7179..349ba1cf5 100644 --- a/packages/xarc-app-dev/src/lib/logger.ts +++ b/packages/xarc-app-dev/src/lib/logger.ts @@ -1,3 +1,4 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; module.exports = require("./winston-logger")(require("winston")); diff --git a/packages/xarc-app-dev/src/lib/module-processor.ts b/packages/xarc-app-dev/src/lib/module-processor.ts index 600220e45..81890de83 100644 --- a/packages/xarc-app-dev/src/lib/module-processor.ts +++ b/packages/xarc-app-dev/src/lib/module-processor.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /** * Take webpack Stat JSON output and group modules by npm packages, @@ -17,6 +18,11 @@ const atModRegex = new RegExp(`([^/]+/[^/]+)/(.+)`); const modRegex = new RegExp(`([^/]+)/(.+)`); class ModuleProcessor { + statJson: any; + modulesByPackage: any; + totalSize: any; + modulesByName: any; + constructor(statJson) { this.statJson = statJson; this.makeModulesByName(); diff --git a/packages/xarc-app-dev/src/lib/stats-mapper.ts b/packages/xarc-app-dev/src/lib/stats-mapper.ts index dff54959b..0507677b8 100644 --- a/packages/xarc-app-dev/src/lib/stats-mapper.ts +++ b/packages/xarc-app-dev/src/lib/stats-mapper.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const _ = require("lodash"); diff --git a/packages/xarc-app-dev/src/lib/stats-utils.ts b/packages/xarc-app-dev/src/lib/stats-utils.ts index 4bbac1321..4e335a4ed 100644 --- a/packages/xarc-app-dev/src/lib/stats-utils.ts +++ b/packages/xarc-app-dev/src/lib/stats-utils.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; const _ = require("lodash"); const ModuleProcessor = require("./module-processor"); @@ -99,7 +100,7 @@ function jsonToHtml(obj, useColors, anchors) { } }; - const table = (array, formats, align, splitter) => { + const table = (array, formats, align, splitter = null) => { const rows = array.length; const cols = array[0].length; const colSizes = new Array(cols); diff --git a/packages/xarc-app-dev/src/lib/utils.ts b/packages/xarc-app-dev/src/lib/utils.ts index 6652bbd0d..115792509 100644 --- a/packages/xarc-app-dev/src/lib/utils.ts +++ b/packages/xarc-app-dev/src/lib/utils.ts @@ -1,7 +1,8 @@ -"use strict"; +import * as readPkgUp from "read-pkg-up"; +import * as pkgUp from "pkg-up"; + const Path = require("path"); const Fs = require("fs"); -const pkg = require("../package.json"); require("../typedef"); const Url = require("url"); @@ -26,7 +27,7 @@ function checkUserBabelRc() { if ( Object.keys(userRc).length === 1 && typeof userRc.extends === "string" && - userRc.extends.indexOf(pkg.name) >= 0 + userRc.extends.indexOf("@xarc/app") >= 0 ) { return "extendsOnly"; } else { @@ -52,9 +53,17 @@ const defaultCreateOptions = { */ const getXarcOptions = userXarcOptions => ({ ...defaultCreateOptions, ...userXarcOptions }); +function getMyPkg() { + const myPkg = readPkgUp.sync({ cwd: __dirname }); + const myDir = Path.dirname(pkgUp.sync({ cwd: __dirname })); + + return { myPkg, myDir }; +} + module.exports = { getOptArchetypeRequire: getOptRequire, formUrl, getXarcOptions, - checkUserBabelRc + checkUserBabelRc, + getMyPkg }; diff --git a/packages/xarc-app-dev/src/lib/webpack-dev-express.ts b/packages/xarc-app-dev/src/lib/webpack-dev-express.ts index c2feb70a4..bb63964e9 100644 --- a/packages/xarc-app-dev/src/lib/webpack-dev-express.ts +++ b/packages/xarc-app-dev/src/lib/webpack-dev-express.ts @@ -1,4 +1,6 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + const AppDevMiddleware = require("./app-dev-middleware"); function setup(app) { diff --git a/packages/xarc-app-dev/src/lib/webpack-dev-fastify.ts b/packages/xarc-app-dev/src/lib/webpack-dev-fastify.ts index 29bf4c10b..fd9a4dad8 100644 --- a/packages/xarc-app-dev/src/lib/webpack-dev-fastify.ts +++ b/packages/xarc-app-dev/src/lib/webpack-dev-fastify.ts @@ -1,4 +1,6 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + /* eslint-disable no-console, no-magic-numbers */ const AppDevMiddleware = require("./app-dev-middleware"); diff --git a/packages/xarc-app-dev/src/lib/webpack-dev-hapi.ts b/packages/xarc-app-dev/src/lib/webpack-dev-hapi.ts index 188f53f3d..01f0d1a65 100644 --- a/packages/xarc-app-dev/src/lib/webpack-dev-hapi.ts +++ b/packages/xarc-app-dev/src/lib/webpack-dev-hapi.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-magic-numbers */ diff --git a/packages/xarc-app-dev/src/lib/webpack-dev-hapi17.ts b/packages/xarc-app-dev/src/lib/webpack-dev-hapi17.ts index 9cfdbd1fb..6df2b7abb 100644 --- a/packages/xarc-app-dev/src/lib/webpack-dev-hapi17.ts +++ b/packages/xarc-app-dev/src/lib/webpack-dev-hapi17.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-console, no-magic-numbers */ diff --git a/packages/xarc-app-dev/src/lib/webpack-dev-koa.ts b/packages/xarc-app-dev/src/lib/webpack-dev-koa.ts index dde95c195..c361ae826 100644 --- a/packages/xarc-app-dev/src/lib/webpack-dev-koa.ts +++ b/packages/xarc-app-dev/src/lib/webpack-dev-koa.ts @@ -1,4 +1,6 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; + const AppDevMiddleware = require("./app-dev-middleware"); function setup(app) { diff --git a/packages/xarc-app-dev/src/lib/winston-logger.ts b/packages/xarc-app-dev/src/lib/winston-logger.ts index 5620e5f05..4edc788a3 100644 --- a/packages/xarc-app-dev/src/lib/winston-logger.ts +++ b/packages/xarc-app-dev/src/lib/winston-logger.ts @@ -1,4 +1,5 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ +export {}; /* eslint-disable no-magic-numbers */ diff --git a/packages/xarc-app-dev/test/spec/dev-admin/dev-fastify.spec.ts b/packages/xarc-app-dev/test/spec/dev-admin/dev-fastify.spec.ts index b2abe62fa..c5a02d78f 100644 --- a/packages/xarc-app-dev/test/spec/dev-admin/dev-fastify.spec.ts +++ b/packages/xarc-app-dev/test/spec/dev-admin/dev-fastify.spec.ts @@ -1,4 +1,9 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, no-invalid-this, max-statements */ + +import { describe, it, beforeEach, afterEach } from "mocha"; +import { expect } from "chai"; + +export {}; const events = require("events"); const fs = require("fs"); @@ -40,7 +45,7 @@ describe("dev-admin-fastify", function() { let reply; function registerFastify() { - const register = require("../../../lib/dev-admin/dev-fastify"); + const register = require("../../../src/lib/dev-admin/dev-fastify"); register(mockFastify); } @@ -75,7 +80,7 @@ describe("dev-admin-fastify", function() { MiddlewareClass.setupCount = 0; MiddlewareClass.processStub = sandbox.stub(); - mockRequire("../../../lib/dev-admin/middleware", MiddlewareClass); + mockRequire("../../../src/lib/dev-admin/middleware", MiddlewareClass); mockRequire("@xarc/app/config/archetype", () => ({ webpack: { devMiddleware: true } })); @@ -84,7 +89,7 @@ describe("dev-admin-fastify", function() { afterEach(() => { mockRequire.stopAll(); sandbox.restore(); - delete require.cache[require.resolve("../../../lib/dev-admin/dev-fastify")]; + delete require.cache[require.resolve("../../../src/lib/dev-admin/dev-fastify")]; }); it("register loads dev and hot middleware", () => { diff --git a/packages/xarc-app-dev/test/spec/dev-admin/log-parser.spec.ts b/packages/xarc-app-dev/test/spec/dev-admin/log-parser.spec.ts index 13c517216..5d4979bf9 100644 --- a/packages/xarc-app-dev/test/spec/dev-admin/log-parser.spec.ts +++ b/packages/xarc-app-dev/test/spec/dev-admin/log-parser.spec.ts @@ -1,7 +1,8 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires */ -const expect = require("chai").expect; -const { parse } = require("../../../lib/dev-admin/log-parser"); +const { parse } = require("../../../src/lib/dev-admin/log-parser"); +import { describe, it } from "mocha"; +import { expect } from "chai"; describe("log-parser", function() { it("should return correct level and message for a simple error", () => { diff --git a/packages/xarc-app-dev/test/spec/dev-admin/webpack-dev-relay.spec.ts b/packages/xarc-app-dev/test/spec/dev-admin/webpack-dev-relay.spec.ts index 4ac6b3e6f..ba2172361 100644 --- a/packages/xarc-app-dev/test/spec/dev-admin/webpack-dev-relay.spec.ts +++ b/packages/xarc-app-dev/test/spec/dev-admin/webpack-dev-relay.spec.ts @@ -1,10 +1,12 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, callback-return */ const { EventEmitter } = require("events"); -const WebpackDevRelay = require("../../../lib/dev-admin/webpack-dev-relay"); +const WebpackDevRelay = require("../../../src/lib/dev-admin/webpack-dev-relay"); const isomorphicConfig = require("isomorphic-loader/lib/config"); const { asyncVerify } = require("run-verify"); const _ = require("lodash"); +import { describe, it } from "mocha"; +import { expect } from "chai"; describe("webpack-dev-relay", function() { it("should clear webpack dev data if dev server exits", () => { diff --git a/packages/xarc-app-dev/test/spec/dev-fastify.spec.ts b/packages/xarc-app-dev/test/spec/dev-fastify.spec.ts index ac322956d..f88931dc1 100644 --- a/packages/xarc-app-dev/test/spec/dev-fastify.spec.ts +++ b/packages/xarc-app-dev/test/spec/dev-fastify.spec.ts @@ -1,5 +1,9 @@ -"use strict"; +/* eslint-disable @typescript-eslint/no-var-requires, callback-return, global-require */ +/* eslint-disable no-unused-expressions, @typescript-eslint/ban-ts-ignore */ + const mockRequire = require("mock-require"); +import { describe, it, before, beforeEach } from "mocha"; +import { expect } from "chai"; describe("dev-fastify", function() { let fakeServer; @@ -25,17 +29,18 @@ describe("dev-fastify", function() { }); it("on request hook is attached", () => { - const fastifyMod = require("../../lib/webpack-dev-fastify"); + const fastifyMod = require("../../src/lib/webpack-dev-fastify"); fastifyMod(fakeServer); expect(hooks.onRequest).exist; }); it("calling request hook sets webpackDev", () => { - const fastifyMod = require("../../lib/webpack-dev-fastify"); + const fastifyMod = require("../../src/lib/webpack-dev-fastify"); fastifyMod(fakeServer); expect(hooks.onRequest).exist; const fakeRequest = { app: {} }; hooks.onRequest(fakeRequest); + // @ts-ignore expect(fakeRequest.app.webpackDev).exist; }); }); diff --git a/packages/xarc-app-dev/test/spec/dev-hapi.spec.ts b/packages/xarc-app-dev/test/spec/dev-hapi.spec.ts index 13013d2bf..3b6bd0f33 100644 --- a/packages/xarc-app-dev/test/spec/dev-hapi.spec.ts +++ b/packages/xarc-app-dev/test/spec/dev-hapi.spec.ts @@ -1,8 +1,13 @@ +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-empty-function */ +/* eslint-disable @typescript-eslint/ban-ts-ignore, no-invalid-this, @typescript-eslint/class-name-casing */ + const mockRequire = require("mock-require"); -const expect = require("chai").expect; const hapiCompat = require("electrode-hapi-compat"); -const moduleName = "../../lib/dev-admin/dev-hapi"; +const moduleName = "../../src/lib/dev-admin/dev-hapi"; + +import { before, beforeEach, describe, it, after, afterEach } from "mocha"; +import { expect } from "chai"; describe("dev-hapi", function() { this.timeout(10000); @@ -17,33 +22,40 @@ describe("dev-hapi", function() { after(() => { mockRequire.stop("@xarc/app/config/archetype"); - mockRequire.stop("../../lib/dev-admin/middleware"); + mockRequire.stop("../../src/lib/dev-admin/middleware"); }); const textCycle = callback => { const mockReply = arg => { + // @ts-ignore mockReply.result.reply = arg; return mockReply; }; mockReply.result = {}; mockReply.continue = () => { + // @ts-ignore mockReply.result.continue = true; return mockReply; }; mockReply.takeover = () => { + // @ts-ignore mockReply.result.takeover = true; return mockReply; }; mockReply.response = arg => { + // @ts-ignore mockReply.result.response = arg; return mockReply; }; mockReply.code = arg => { + // @ts-ignore mockReply.result.code = arg; return mockReply; }; mockReply.header = (key, value) => { + // @ts-ignore mockReply.result.headers = mockReply.result.headers || {}; + // @ts-ignore mockReply.result.headers[key] = value; return mockReply; }; @@ -56,7 +68,7 @@ describe("dev-hapi", function() { } setup() {} } - mockRequire("../../lib/dev-admin/middleware", mockMiddleware); + mockRequire("../../src/lib/dev-admin/middleware", mockMiddleware); let register = require(moduleName); register = register.register || register; register( @@ -74,7 +86,7 @@ describe("dev-hapi", function() { it("Hapi16: if replyFile is called with a valid file then return 200", () => { hapiCompat.hapiVersion = 16; textCycle(cycle => { - const { result } = cycle.replyFile("./xclap.js"); + const { result } = cycle.replyFile("./require.js"); expect(result.code).to.equal(200); expect(result).to.have.any.keys("response"); expect(result.headers["Content-Type"]).to.equal("application/javascript"); @@ -92,7 +104,7 @@ describe("dev-hapi", function() { it("Hapi17: if replyFile is called with a valid file then return 200", () => { hapiCompat.hapiVersion = 17; textCycle(cycle => { - const { result } = cycle.replyFile("./xclap.js"); + const { result } = cycle.replyFile("./require.js"); expect(result.code).to.equal(200); expect(result.takeover).to.equal(true); expect(result).to.have.any.keys("response"); @@ -111,7 +123,7 @@ describe("dev-hapi", function() { it("Hapi18: if replyFile is called with a valid file then return 200", () => { hapiCompat.hapiVersion = 18; textCycle(cycle => { - const { result } = cycle.replyFile("./xclap.js"); + const { result } = cycle.replyFile("./require.js"); expect(result.code).to.equal(200); expect(result.takeover).to.equal(true); expect(result).to.have.any.keys("response"); diff --git a/packages/xarc-app-dev/test/spec/extract.style.spec.ts b/packages/xarc-app-dev/test/spec/extract.style.spec.ts index fa2621f98..17f0266c6 100644 --- a/packages/xarc-app-dev/test/spec/extract.style.spec.ts +++ b/packages/xarc-app-dev/test/spec/extract.style.spec.ts @@ -1,7 +1,13 @@ -const expect = require("chai").expect; -const archetype = require("../../config/archetype")(); +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-empty-function */ +/* eslint-disable @typescript-eslint/ban-ts-ignore, no-invalid-this, @typescript-eslint/class-name-casing */ +/* eslint-disable no-unused-expressions, max-nested-callbacks, no-unused-expressions */ + +const archetype = require("../../src/config/archetype")(); const moduleName = "@xarc/webpack/lib/partials/extract-style"; +import { describe, it, afterEach } from "mocha"; +import { expect } from "chai"; + // TODO: should move to xarc-webpack describe.skip("@xarc/app-dev extract-styles", function() { this.timeout(10000); diff --git a/packages/xarc-app-dev/test/spec/generate-config.spec.ts b/packages/xarc-app-dev/test/spec/generate-config.spec.ts index 74093be98..8d56ea85c 100644 --- a/packages/xarc-app-dev/test/spec/generate-config.spec.ts +++ b/packages/xarc-app-dev/test/spec/generate-config.spec.ts @@ -1,9 +1,14 @@ +/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-empty-function */ +/* eslint-disable @typescript-eslint/ban-ts-ignore, no-invalid-this, @typescript-eslint/class-name-casing */ + const mockRequire = require("mock-require"); -const expect = require("chai").expect; const Path = require("path"); const moduleName = "@xarc/webpack/lib/util/generate-config"; +import { before, beforeEach, describe, it, after, afterEach } from "mocha"; +import { expect } from "chai"; + // TODO: should move to xarc-webpack describe.skip("generate-config", function() { this.timeout(10000); diff --git a/packages/xarc-app-dev/tsconfig.json b/packages/xarc-app-dev/tsconfig.json new file mode 100644 index 000000000..fe1aef8e2 --- /dev/null +++ b/packages/xarc-app-dev/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "outDir": "dist", + "lib": ["es2018"], + "allowJs": true, + "module": "CommonJS", + "esModuleInterop": false, + "target": "ES2018", + "preserveConstEnums": true, + "sourceMap": true, + "declaration": true, + "types": ["node"], + "forceConsistentCasingInFileNames": true, + "noImplicitReturns": true, + "alwaysStrict": true, + "strictFunctionTypes": true + }, + "include": ["src"], + "exclude": ["node_modules", "lib", "config", "dist", "src/**/*.js"] +} diff --git a/packages/xarc-app-dev/xclap.js b/packages/xarc-app-dev/xclap.js deleted file mode 100644 index 65b0c2da6..000000000 --- a/packages/xarc-app-dev/xclap.js +++ /dev/null @@ -1 +0,0 @@ -require("@xarc/module-dev")(); diff --git a/packages/xarc-app-dev/xrun-tasks.ts b/packages/xarc-app-dev/xrun-tasks.ts new file mode 100644 index 000000000..b5d248ffe --- /dev/null +++ b/packages/xarc-app-dev/xrun-tasks.ts @@ -0,0 +1,46 @@ +import * as Path from "path"; +import * as xrun from "@xarc/run"; +import * as scanDir from "filter-scan-dir"; +import { loadTasks } from "@xarc/module-dev"; +import * as xsh from "xsh"; +import * as _ from "lodash"; +import * as Fs from "fs"; + +loadTasks({ xrun }); + +const { exec, serial } = xrun; + +xrun.load("user", { + moveDist: () => { + const scanned = scanDir.sync({ + dir: "src", + includeRoot: true, + ignoreExt: [".ts"] + }); + + _.uniq(scanned.map(f => Path.dirname(f).replace("src", "dist"))).forEach(d => + // @ts-ignore + xsh.$.mkdir("-p", d) + ); + + // @ts-ignore + scanned.forEach(f => xsh.$.cp(f, f.replace("src", "dist"))); + + const scanMaps = scanDir.sync({ + dir: "dist", + includeRoot: true, + filterExt: [".map"] + }); + + scanMaps.forEach(f => { + const fname = Path.resolve(f); + const mapData = JSON.parse(Fs.readFileSync(fname).toString()); + mapData.sources = mapData.sources.map(s => Path.relative("..", s)); + Fs.writeFileSync(fname, JSON.stringify(mapData) + "\n"); + }); + + return serial(exec("shx rm -rf config lib", {}), exec("shx mv dist/* .", {}), () => + Fs.rmdirSync("dist") + ); + } +});