Skip to content

Commit

Permalink
refactor: backport latest projector changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius committed Aug 28, 2021
1 parent f1b955b commit cc0a00d
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 32 deletions.
13 changes: 6 additions & 7 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

// ? https://nodejs.org/en/about/releases
const NODE_LTS = 'maintained node versions';

const debug = require('debug')(`${require('./package.json').name}:babel-config`);
const pkgName = require('./package.json').name;
const debug = require('debug')(`${pkgName}:babel-config`);
const { determineModuleTypes } = require('webpack-node-module-types/sync');

// ? Fix relative local imports referencing package.json (.dist/esm/...)
const transformRenameImport = [
'transform-rename-import',
{
replacements: [
{ original: '../package.json', replacement: '../../package.json' },
// ? see: https://bit.ly/3Chxmlb
{ original: '../package.json.mjs', replacement: '../../package.json' }
]
// ? See: https://bit.ly/38hFTa8
replacements: [{ original: 'package', replacement: `${pkgName}/package.json` }]
}
];

Expand All @@ -29,6 +27,7 @@ module.exports = {
[
'transform-default-named-imports',
{
test: [...determineModuleTypes().cjs, 'package'],
exclude: [
/* /^next([/?#].+)?/, /^mongodb([/?#].+)?/ */
]
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@
"unique-filename": "^1.1.1",
"webpack": "^5.51.1",
"webpack-cli": "^4.8.0",
"webpack-node-externals": "^3.0.0"
"webpack-node-externals": "^3.0.0",
"webpack-node-module-types": "^1.0.7"
},
"engines": {
"node": ">=12.x"
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { name as pkgName } from '../package.json';
import { name as pkgName } from 'package';
import { configureProgram } from './index';
import debugFactory from 'debug';

Expand Down
2 changes: 1 addition & 1 deletion src/git-lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { name as pkgName } from '../package.json';
import { name as pkgName } from 'package';
import debugFactory from 'debug';
import git from 'simple-git';
import ancestorPath from 'common-ancestor-path';
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { name as pkgName } from '../package.json';
import { name as pkgName } from 'package';
import { parse as parsePath, basename } from 'path';
import yargs from 'yargs/yargs';
import debugFactory from 'debug';
Expand Down
2 changes: 1 addition & 1 deletion test/integration-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable jest/no-conditional-expect */
import { name as pkgName, bin as pkgBin } from '../package.json';
import { name as pkgName, bin as pkgBin } from 'package';
import { promises as fs } from 'fs';
import fixtures from './fixtures';
import del from 'del';
Expand Down
2 changes: 1 addition & 1 deletion test/integration-node.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import debugFactory from 'debug';
import { name as pkgName, version as pkgVersion, main as pkgMain } from '../package.json';
import { name as pkgName, version as pkgVersion, main as pkgMain } from 'package';
import {
run,
mockFixtureFactory,
Expand Down
2 changes: 1 addition & 1 deletion test/integration-webpack.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import debugFactory from 'debug';
import { name as pkgName, version as pkgVersion, main as pkgMain } from '../package.json';
import { name as pkgName, version as pkgVersion, main as pkgMain } from 'package';
import {
run,
mockFixtureFactory,
Expand Down
2 changes: 1 addition & 1 deletion test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { name as pkgName, version as pkgVersion } from '../package.json';
import { name as pkgName, version as pkgVersion } from 'package';
import { tmpdir } from 'os';
import { promises as fs } from 'fs';
import { resolve } from 'path';
Expand Down
18 changes: 17 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,25 @@
"noUnusedParameters": true,
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
// ! If changed, also update these aliases in jest.config.js,
// ! webpack.config.js, next.config.ts, and .eslintrc.js
"universe/*": ["src/*"],
"multiverse/*": ["lib/*"],
"testverse/*": ["test/*"],
"externals/*": ["external-scripts/*"],
"types/*": ["types/*"],
"package": ["package.json"]
},
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"ESNext",
"DOM",
"WebWorker.ImportScripts",
"ScriptHost",
"DOM.Iterable"
],
"skipLibCheck": true,
"noEmit": true,
"esModuleInterop": true,
Expand Down
63 changes: 48 additions & 15 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

// This webpack config is used to transpile src to dist, compile externals,
// compile executables, etc

Expand All @@ -7,6 +8,15 @@ const { verifyEnvironment } = require('./expect-env');
const nodeExternals = require('webpack-node-externals');
const debug = require('debug')(`${require('./package.json').name}:webpack-config`);

const IMPORT_ALIASES = {
universe: `${__dirname}/src/`,
multiverse: `${__dirname}/lib/`,
testverse: `${__dirname}/test/`,
externals: `${__dirname}/external-scripts/`,
types: `${__dirname}/types/`,
package: `${__dirname}/package.json`
};

let sanitizedEnv = {};
let { NODE_ENV: nodeEnv, ...sanitizedProcessEnv } = {
...process.env,
Expand Down Expand Up @@ -73,23 +83,36 @@ const libConfig = {
errorDetails: true
},

resolve: { extensions: ['.ts', '.wasm', '.mjs', '.cjs', '.js', '.json'] },
resolve: {
extensions: ['.ts', '.wasm', '.mjs', '.cjs', '.js', '.json'],
// ! If changed, also update these aliases in tsconfig.json,
// ! jest.config.js, next.config.ts, and .eslintrc.js
alias: IMPORT_ALIASES
},
module: {
rules: [{ test: /\.(ts|js)x?$/, loader: 'babel-loader', exclude: /node_modules/ }]
},
optimization: { usedExports: true },
ignoreWarnings: [/critical dependency: the request of a dependency is an expression/i],
plugins: [...envPlugins]
};

/*const externalsConfig = {
/* const externalsConfig = {
name: 'externals',
mode: 'production',
target: 'node',
node: false,
entry: {
dummy: `${__dirname}/external-scripts/dummy.ts`
'ban-hammer': `${__dirname}/external-scripts/ban-hammer.ts`,
'prune-data': `${__dirname}/external-scripts/prune-data.ts`,
// 'initialize-data': `${__dirname}/external-scripts/initialize-data/index.ts`,
// 'worker-friends': `${__dirname}/external-scripts/initialize-data/worker-friends.ts`,
// 'worker-memes': `${__dirname}/external-scripts/initialize-data/worker-memes.ts`,
// 'worker-interactions': `${__dirname}/external-scripts/initialize-data/worker-interactions.ts`,
// 'worker-chats': `${__dirname}/external-scripts/initialize-data/worker-chats.ts`,
// 'simulate-activity': `${__dirname}/external-scripts/simulate-activity/index.ts`
},
output: {
Expand All @@ -107,18 +130,28 @@ const libConfig = {
errorDetails: true
},
resolve: { extensions: ['.ts', '.wasm', '.mjs', '.cjs', '.js', '.json'] },
resolve: {
extensions: ['.ts', '.wasm', '.mjs', '.cjs', '.js', '.json'],
// ! If changed, also update these aliases in tsconfig.json,
// ! jest.config.js, next.config.ts, and .eslintrc.js
alias: IMPORT_ALIASES
},
module: {
rules: [{ test: /\.(ts|js)x?$/, loader: 'babel-loader', exclude: /node_modules/ }]
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: 'babel-loader'
}
]
},
optimization: { usedExports: true },
ignoreWarnings: [/critical dependency: the request of a dependency is an expression/i],
plugins: [
...envPlugins,
// * ▼ For non-bundled externals, make entry file executable w/ shebang
new BannerPlugin({ banner: '#!/usr/bin/env node', raw: true, entryOnly: true })
]
};*/
}; */

const cliConfig = {
name: 'cli',
Expand All @@ -143,20 +176,20 @@ const cliConfig = {
errorDetails: true
},

resolve: { extensions: ['.ts', '.wasm', '.mjs', '.cjs', '.js', '.json'] },
resolve: {
extensions: ['.ts', '.wasm', '.mjs', '.cjs', '.js', '.json'],
// ! If changed, also update these aliases in tsconfig.json,
// ! jest.config.js, next.config.ts, and .eslintrc.js
alias: IMPORT_ALIASES
},
module: {
rules: [{ test: /\.(ts|js)x?$/, loader: 'babel-loader', exclude: /node_modules/ }]
},
optimization: { usedExports: true },
ignoreWarnings: [/critical dependency: the request of a dependency is an expression/i],
plugins: [
...envPlugins,
// * ▼ For bundled CLI applications, make entry file executable w/ shebang
new BannerPlugin({
banner: '#!/usr/bin/env node',
raw: true,
entryOnly: true
})
new BannerPlugin({ banner: '#!/usr/bin/env node', raw: true, entryOnly: true })
]
};

Expand Down

0 comments on commit cc0a00d

Please sign in to comment.