chore: eval

This commit is contained in:
cha0s 2021-03-23 02:20:52 -05:00
parent 3c96ccd969
commit 18aa901c1b
13 changed files with 93 additions and 55 deletions

View File

@ -7,6 +7,7 @@ import {
} from 'path'; } from 'path';
import Latus from './latus'; import Latus from './latus';
import R from './require';
const { const {
LATUS_BABEL_CONFIG = require.resolve('@latus/build/build/.babelrc.js'), LATUS_BABEL_CONFIG = require.resolve('@latus/build/build/.babelrc.js'),
@ -14,26 +15,24 @@ const {
} = process.env; } = process.env;
export default (latus) => (neutrino) => { export default (latus) => (neutrino) => {
// eslint-disable-next-line no-eval const airbnb = R('@neutrinojs/airbnb');
const r = eval('require');
const airbnb = r('@neutrinojs/airbnb');
airbnb({ airbnb({
eslint: { eslint: {
cache: false, cache: false,
baseConfig: r(LATUS_ESLINT_DEFAULTS), baseConfig: R(LATUS_ESLINT_DEFAULTS),
}, },
})(neutrino); })(neutrino);
const clean = r('@neutrinojs/clean'); const clean = R('@neutrinojs/clean');
clean({ clean({
cleanOnceBeforeBuildPatterns: ['**/*.hot-update.*'], cleanOnceBeforeBuildPatterns: ['**/*.hot-update.*'],
})(neutrino); })(neutrino);
const {EnvironmentPlugin} = r('webpack'); const {EnvironmentPlugin} = R('webpack');
neutrino.config neutrino.config
.plugin('environment') .plugin('environment')
.use(EnvironmentPlugin, [{ .use(EnvironmentPlugin, [{
SIDE: 'server', SIDE: 'server',
}]); }]);
const node = r('@neutrinojs/node'); const node = R('@neutrinojs/node');
node({ node({
babel: { babel: {
configFile: LATUS_BABEL_CONFIG, configFile: LATUS_BABEL_CONFIG,
@ -44,7 +43,7 @@ export default (latus) => (neutrino) => {
const config = {}; const config = {};
[plugin, `${plugin}/server`].forEach((path) => { [plugin, `${plugin}/server`].forEach((path) => {
try { try {
r.resolve(path); R.resolve(path);
config[path] = {}; config[path] = {};
} }
// eslint-disable-next-line no-empty // eslint-disable-next-line no-empty
@ -65,7 +64,7 @@ export default (latus) => (neutrino) => {
.rules.store.get('compile') .rules.store.get('compile')
.uses.store.get('babel') .uses.store.get('babel')
.store.get('options'); .store.get('options');
r('@babel/register')({ R('@babel/register')({
plugins: babelOptions.plugins, plugins: babelOptions.plugins,
presets: babelOptions.presets, presets: babelOptions.presets,
}); });
@ -87,7 +86,7 @@ export default (latus) => (neutrino) => {
}); });
source.push('}'); source.push('}');
// Everything's a simulation... // Everything's a simulation...
const virtual = r.resolve(`${__dirname}/virtual`); const virtual = R.resolve(`${__dirname}/virtual`);
neutrino.config neutrino.config
.entry('index') .entry('index')
.add(virtual); .add(virtual);
@ -102,12 +101,12 @@ export default (latus) => (neutrino) => {
neutrino.config neutrino.config
.entry('index') .entry('index')
.add('@latus/core/start'); .add('@latus/core/start');
const mocha = r('@neutrinojs/mocha'); const mocha = R('@neutrinojs/mocha');
mocha()(neutrino); mocha()(neutrino);
if (process.env.LATUS_LINTING) { if (process.env.LATUS_LINTING) {
return; return;
} }
const nodeExternals = r('webpack-node-externals'); const nodeExternals = R('webpack-node-externals');
const allowlist = [ const allowlist = [
/^@latus\/core\/virtual$/, /^@latus\/core\/virtual$/,
]; ];
@ -117,7 +116,7 @@ export default (latus) => (neutrino) => {
.prepend('dotenv/config'); .prepend('dotenv/config');
allowlist.push(/^webpack/); allowlist.push(/^webpack/);
paths.forEach((path) => { paths.forEach((path) => {
const resolved = resolve(r.resolve(path)); const resolved = resolve(R.resolve(path));
// Cheating for now... // Cheating for now...
const parts = resolved.split('/'); const parts = resolved.split('/');
parts.splice(parts.indexOf('packages') + 2, 0, 'src'); parts.splice(parts.indexOf('packages') + 2, 0, 'src');
@ -134,8 +133,8 @@ export default (latus) => (neutrino) => {
allowlist, allowlist,
})); }));
const entries = neutrino.config.entryPoints.store.get('index').store; const entries = neutrino.config.entryPoints.store.get('index').store;
if (entries.has(`${r.resolve('webpack/hot/poll')}?1000`)) { if (entries.has(`${R.resolve('webpack/hot/poll')}?1000`)) {
entries.delete(`${r.resolve('webpack/hot/poll')}?1000`); entries.delete(`${R.resolve('webpack/hot/poll')}?1000`);
const entriesArray = Array.from(entries); const entriesArray = Array.from(entries);
entriesArray.unshift('webpack/hot/signal'); entriesArray.unshift('webpack/hot/signal');
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign

View File

@ -67,22 +67,20 @@ export default (
.sort(([lname], [rname]) => (lname < rname ? -1 : 1)) .sort(([lname], [rname]) => (lname < rname ? -1 : 1))
.map(([type, Class]) => { .map(([type, Class]) => {
const thisUid = uid++; const thisUid = uid++;
// TODO: I think we can do computed class members now. class Subclass extends Class {
const source = `
(${type}) => class Gathered${type} extends ${type} {
static get ${idAttribute}() {
return ${thisUid};
}
static get ${typeAttribute}() {
return '${type}';
}
static get [idAttribute]() {
return thisUid;
} }
`;
// eslint-disable-next-line no-eval static get [typeAttribute]() {
const Subclass = eval(source)(Class); return type;
}
}
if (!Subclass.name) {
Subclass.name = type;
}
fromId[thisUid] = Subclass; fromId[thisUid] = Subclass;
return [ return [
type, type,

View File

@ -11,6 +11,7 @@ export {compose, fastApply} from './function';
export {decorateWithLatus, gatherWithLatus, default as gather} from './gather'; export {decorateWithLatus, gatherWithLatus, default as gather} from './gather';
export {default as Middleware} from './middleware'; export {default as Middleware} from './middleware';
export {default as Latus} from './latus'; export {default as Latus} from './latus';
export {default as require} from './require';
export * from './string'; export * from './string';
export const Class = class {}; export const Class = class {};

View File

@ -8,6 +8,7 @@ import without from 'lodash.without';
import Middleware from './middleware'; import Middleware from './middleware';
import readConfig from './read-config'; import readConfig from './read-config';
import R from './require';
const debug = D('@latus/core/latus'); const debug = D('@latus/core/latus');
@ -56,8 +57,6 @@ export default class Latus {
} }
static create(config = readConfig()) { static create(config = readConfig()) {
// eslint-disable-next-line no-eval
const R = eval('require');
const paths = flatten( const paths = flatten(
Object.keys(config).map((path) => [ Object.keys(config).map((path) => [
this.runtimePath(path), this.runtimePath(path),
@ -211,7 +210,6 @@ export default class Latus {
} }
static mock(modules, config = {}) { static mock(modules, config = {}) {
// eslint-disable-next-line no-eval
return new Latus({ return new Latus({
config: { config: {
...Object.fromEntries(Object.keys(modules).map((path) => [path, {}])), ...Object.fromEntries(Object.keys(modules).map((path) => [path, {}])),
@ -222,8 +220,6 @@ export default class Latus {
} }
static runtimePath(path) { static runtimePath(path) {
// eslint-disable-next-line no-eval
const R = eval('require');
try { try {
const local = join(process.cwd(), 'src', path); const local = join(process.cwd(), 'src', path);
R.resolve(local); R.resolve(local);

View File

@ -0,0 +1,2 @@
// eslint-disable-next-line no-eval
export default eval('"undefined" !== typeof require ? require : () => {}');

View File

@ -1,5 +1,7 @@
const uniq = require('lodash.uniq'); const uniq = require('lodash.uniq');
const {require: R} = require('@latus/core');
module.exports = async (latus, req) => { module.exports = async (latus, req) => {
const plugins = await latus.invokeReduceAsync( const plugins = await latus.invokeReduceAsync(
'@latus/http/plugins', '@latus/http/plugins',
@ -19,8 +21,7 @@ module.exports = async (latus, req) => {
} }
[plugin, `${plugin}/client`].forEach((path) => { [plugin, `${plugin}/client`].forEach((path) => {
try { try {
// eslint-disable-next-line no-eval R.resolve(path);
eval('require.resolve')(path);
config[path] = {}; config[path] = {};
} }
// eslint-disable-next-line no-empty // eslint-disable-next-line no-empty

View File

@ -2,12 +2,11 @@
const {isAbsolute, join} = require('path'); const {isAbsolute, join} = require('path');
const fs = require('fs'); const fs = require('fs');
const {require: R} = require('@latus/core');
const {DefinePlugin} = require('webpack'); const {DefinePlugin} = require('webpack');
module.exports = () => (neutrino) => { module.exports = () => (neutrino) => {
// eslint-disable-next-line no-eval const copy = R('@neutrinojs/copy');
const r = eval('require');
const copy = r('@neutrinojs/copy');
copy({ copy({
patterns: [{ patterns: [{
from: join(neutrino.options.root, 'src', 'assets'), from: join(neutrino.options.root, 'src', 'assets'),

View File

@ -1,17 +1,15 @@
const {Latus} = require('@latus/core'); const {Latus, require: R} = require('@latus/core');
const clientPlugins = require('../client-plugins'); const clientPlugins = require('../client-plugins');
module.exports = async (latus) => { module.exports = async (latus) => {
const config = await clientPlugins(latus); const config = await clientPlugins(latus);
return (neutrino) => { return (neutrino) => {
// eslint-disable-next-line no-eval
const r = eval('require');
const babelOptions = neutrino.config.module const babelOptions = neutrino.config.module
.rules.store.get('compile') .rules.store.get('compile')
.uses.store.get('babel') .uses.store.get('babel')
.store.get('options'); .store.get('options');
r('@babel/register')({ R('@babel/register')({
plugins: babelOptions.plugins, plugins: babelOptions.plugins,
presets: babelOptions.presets, presets: babelOptions.presets,
}); });
@ -22,7 +20,7 @@ module.exports = async (latus) => {
.map((path) => Latus.runtimePath(`${path}/index.css.js`)) .map((path) => Latus.runtimePath(`${path}/index.css.js`))
.filter((path) => !!path); .filter((path) => !!path);
const cssAppliers = cssPaths.map((path) => `require('${path}')`).join(';'); const cssAppliers = cssPaths.map((path) => `require('${path}')`).join(';');
const virtual = r.resolve('@latus/http/virtual'); const virtual = R.resolve('@latus/http/virtual');
const source = [ const source = [
`${cssAppliers}`, `${cssAppliers}`,
'export default {', 'export default {',
@ -49,7 +47,7 @@ module.exports = async (latus) => {
const testPaths = paths const testPaths = paths
.map((path) => [path, Latus.runtimePath(`${path}/test`)]) .map((path) => [path, Latus.runtimePath(`${path}/test`)])
.filter(([, path]) => !!path); .filter(([, path]) => !!path);
const tests = r.resolve('@latus/http/tests'); const tests = R.resolve('@latus/http/tests');
neutrino.config.module neutrino.config.module
.rule(tests) .rule(tests)
.test(tests) .test(tests)

View File

@ -2,7 +2,7 @@ import {createReadStream} from 'fs';
import {createServer, ServerResponse} from 'http'; import {createServer, ServerResponse} from 'http';
import {dirname, join} from 'path'; import {dirname, join} from 'path';
import {arrayFlatten, Latus} from '@latus/core'; import {arrayFlatten, Latus, require as R} from '@latus/core';
import express from 'express'; import express from 'express';
// eslint-disable-next-line import/no-extraneous-dependencies // eslint-disable-next-line import/no-extraneous-dependencies
import httpProxy from 'http-proxy'; import httpProxy from 'http-proxy';
@ -49,8 +49,7 @@ export const createHttpServer = async (latus) => {
.map((path) => Latus.runtimePath(path)) .map((path) => Latus.runtimePath(path))
.filter((path) => !!Latus.runtimePath(`${path}/test`)) .filter((path) => !!Latus.runtimePath(`${path}/test`))
.map((path) => { .map((path) => {
// eslint-disable-next-line no-eval const staticPath = dirname(R.resolve(path));
const staticPath = dirname(eval('require').resolve(path));
return express.static(staticPath, {redirect: false}); return express.static(staticPath, {redirect: false});
}); });
for (let i = 0; i < middlewares.length; i++) { for (let i = 0; i < middlewares.length; i++) {

View File

@ -1,5 +1,7 @@
import {spawn} from 'child_process'; import {spawn} from 'child_process';
import {require as R} from '@latus/core';
import {createHttpServer} from './http'; import {createHttpServer} from './http';
const { const {
@ -23,8 +25,8 @@ export default {
!process.argv.find((arg) => '--watch' === arg) !process.argv.find((arg) => '--watch' === arg)
|| process.argv.find((arg) => 'production' === arg) || process.argv.find((arg) => 'production' === arg)
) { ) {
// eslint-disable-next-line global-require, no-eval, no-param-reassign // eslint-disable-next-line no-param-reassign
configs.http = eval('require')('./build/.neutrinorc'); configs.http = R('./build/.neutrinorc');
} }
else if (-1 === excludeBuilds.indexOf('http')) { else if (-1 === excludeBuilds.indexOf('http')) {
const binary = `$(npm --prefix ${process.cwd()} bin)/webpack-dev-server`; const binary = `$(npm --prefix ${process.cwd()} bin)/webpack-dev-server`;

View File

@ -24,6 +24,7 @@
], ],
"dependencies": { "dependencies": {
"@hot-loader/react-dom": "^17.0.1", "@hot-loader/react-dom": "^17.0.1",
"@latus/core": "^2.0.0",
"@neutrinojs/react": "^9.4.0", "@neutrinojs/react": "^9.4.0",
"autoprefixer": "^9.8.6", "autoprefixer": "^9.8.6",
"debug": "4.3.1", "debug": "4.3.1",

View File

@ -1,12 +1,12 @@
const {dirname} = require('path'); const {dirname} = require('path');
const {require: R} = require('@latus/core');
const react = require('@neutrinojs/react'); const react = require('@neutrinojs/react');
// eslint-disable-next-line no-eval const {resolve} = R;
const rr = eval('require').resolve;
const { const {
LATUS_BABEL_CONFIG = rr('@latus/build/build/.babelrc.js'), LATUS_BABEL_CONFIG = resolve('@latus/build/build/.babelrc.js'),
LATUS_POSTCSS_CONFIG = rr('@latus/build/build/postcss.config.js'), LATUS_POSTCSS_CONFIG = resolve('@latus/build/build/postcss.config.js'),
} = process.env; } = process.env;
module.exports = () => (neutrino) => { module.exports = () => (neutrino) => {

View File

@ -932,6 +932,20 @@
webpack "^4" webpack "^4"
webpack-cli "^3" webpack-cli "^3"
"@latus/core@^2.0.0":
version "2.0.0"
resolved "http://npm.cha0sdev/@latus%2fcore/-/core-2.0.0.tgz#12a0f3c11c9832a60e6726ea74ce0ae9b45e9faf"
integrity sha512-JMxgl8Qsvby2OKtzXEs7cjamvsgVxEbJXbjebsmDl+J9Cq5513/4Xpq37EYYvT6FEZpoHFoIkQsaG+89JQzTwg==
dependencies:
autoprefixer "^9.8.6"
debug "4.3.1"
js-yaml "3.14.0"
lodash.flatten "^4.4.0"
lodash.get "^4.4.2"
lodash.set "^4.3.2"
mkdirp "^1.0.4"
webpack-virtual-modules "^0.4.1"
"@neutrinojs/airbnb@^9.4.0": "@neutrinojs/airbnb@^9.4.0":
version "9.5.0" version "9.5.0"
resolved "http://npm.cha0sdev/@neutrinojs%2fairbnb/-/airbnb-9.5.0.tgz#87cfc09c4237a2da632c80d7b91ad447a5e0b3f2" resolved "http://npm.cha0sdev/@neutrinojs%2fairbnb/-/airbnb-9.5.0.tgz#87cfc09c4237a2da632c80d7b91ad447a5e0b3f2"
@ -4254,6 +4268,14 @@ js-base64@^2.1.8:
resolved "http://npm.cha0sdev/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" resolved "http://npm.cha0sdev/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
js-yaml@3.14.0:
version "3.14.0"
resolved "http://npm.cha0sdev/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482"
integrity sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"
js-yaml@4.0.0: js-yaml@4.0.0:
version "4.0.0" version "4.0.0"
resolved "http://npm.cha0sdev/js-yaml/-/js-yaml-4.0.0.tgz#f426bc0ff4b4051926cd588c71113183409a121f" resolved "http://npm.cha0sdev/js-yaml/-/js-yaml-4.0.0.tgz#f426bc0ff4b4051926cd588c71113183409a121f"
@ -4481,11 +4503,26 @@ lodash.clonedeep@^4.5.0:
resolved "http://npm.cha0sdev/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" resolved "http://npm.cha0sdev/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8= integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=
lodash.flatten@^4.4.0:
version "4.4.0"
resolved "http://npm.cha0sdev/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"
integrity sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=
lodash.get@^4.4.2:
version "4.4.2"
resolved "http://npm.cha0sdev/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=
lodash.omit@^4.5.0: lodash.omit@^4.5.0:
version "4.5.0" version "4.5.0"
resolved "http://npm.cha0sdev/lodash.omit/-/lodash.omit-4.5.0.tgz#6eb19ae5a1ee1dd9df0b969e66ce0b7fa30b5e60" resolved "http://npm.cha0sdev/lodash.omit/-/lodash.omit-4.5.0.tgz#6eb19ae5a1ee1dd9df0b969e66ce0b7fa30b5e60"
integrity sha1-brGa5aHuHdnfC5aeZs4Lf6MLXmA= integrity sha1-brGa5aHuHdnfC5aeZs4Lf6MLXmA=
lodash.set@^4.3.2:
version "4.3.2"
resolved "http://npm.cha0sdev/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
integrity sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=
lodash@^4.0.0, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@~4.17.10: lodash@^4.0.0, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@~4.17.10:
version "4.17.20" version "4.17.20"
resolved "http://npm.cha0sdev/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" resolved "http://npm.cha0sdev/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
@ -4741,7 +4778,7 @@ mkdirp@^0.5.1, mkdirp@^0.5.3:
dependencies: dependencies:
minimist "^1.2.5" minimist "^1.2.5"
mkdirp@^1.0.3: mkdirp@^1.0.3, mkdirp@^1.0.4:
version "1.0.4" version "1.0.4"
resolved "http://npm.cha0sdev/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" resolved "http://npm.cha0sdev/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
@ -7050,6 +7087,11 @@ webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-sources@^1.4.1:
source-list-map "^2.0.0" source-list-map "^2.0.0"
source-map "~0.6.1" source-map "~0.6.1"
webpack-virtual-modules@^0.4.1:
version "0.4.2"
resolved "http://npm.cha0sdev/webpack-virtual-modules/-/webpack-virtual-modules-0.4.2.tgz#68ce4479df7334a491b7a3f3bead47fe382947d9"
integrity sha512-OUsT1VZhArN8nY7g6mMlw91HWnXcNXsIQjsQ83WteF4ViZ6YXqF2sWKOTDIZ0H+PPiApQdszLdZIrD7NNlU0Yw==
webpack@^4: webpack@^4:
version "4.46.0" version "4.46.0"
resolved "http://npm.cha0sdev/webpack/-/webpack-4.46.0.tgz#bf9b4404ea20a073605e0a011d188d77cb6ad542" resolved "http://npm.cha0sdev/webpack/-/webpack-4.46.0.tgz#bf9b4404ea20a073605e0a011d188d77cb6ad542"