Skip to content

Remove babel transpilation step for server. #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .core/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (semver.satisfies(semver.coerce(babelCoreVersion), '^7.4.0')) {
}
}

require('./reactium.log');
require('./reactium.log.cjs');

global.ReactiumBabel = ReactiumBabel;

Expand Down
26 changes: 19 additions & 7 deletions .core/boot-hooks.js → .core/boot-hooks.mjs
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
import path from 'path';
import _ from 'underscore';
const globby = require('./globby-patch').sync;
import path from 'node:path';
import globbyPatched from './globby-patch.js'
import { dirname } from '@atomic-reactor/dirname';

const __dirname = dirname(import.meta.url);
const globby = globbyPatched.sync;

global.rootPath = path.resolve(__dirname, '..');

module.exports = async () => {
export default async () => {
// include boot DDD artifacts
if (!global.bootHooks) {
global.bootHooks = globby([
`${rootPath}/.core/**/reactium-boot.js`,
`${rootPath}/.core/**/reactium-boot.mjs`,
`${rootPath}/.core/**/reactium-boot.cjs`,
`${rootPath}/src/**/reactium-boot.js`,
`${rootPath}/src/**/reactium-boot.mjs`,
`${rootPath}/src/**/reactium-boot.cjs`,
`${rootPath}/reactium_modules/**/reactium-boot.js`,
`${rootPath}/reactium_modules/**/reactium-boot.mjs`,
`${rootPath}/reactium_modules/**/reactium-boot.cjs`,
`${rootPath}/node_modules/**/reactium-plugin/**/reactium-boot.js`,
`${rootPath}/node_modules/**/reactium-plugin/**/reactium-boot.mjs`,
`${rootPath}/node_modules/**/reactium-plugin/**/reactium-boot.cjs`,
]);
}

if (!global.bootHookLoaded) {
DEBUG('Loading boot hooks.');
global.bootHookLoaded = [];
global.bootHooks.map(item => {
for (const item of global.bootHooks) {
if (!bootHookLoaded.includes(item)) {
const p = path.normalize(item);
require(p);
await import(p);
bootHookLoaded.push(item);
}
});

}
ReactiumBoot.Hook.runSync('sdk-init', ReactiumBoot);
await ReactiumBoot.Hook.run('sdk-init', ReactiumBoot);
} else {
Expand Down
2 changes: 1 addition & 1 deletion .core/gulp.bootup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = require('./gulp.config');
const webpackConfig = require('./webpack.config')(config);
const chalk = require('chalk');

require('./reactium.log');
require('./reactium.log.cjs');

global.ReactiumGulp = ReactiumGulp;

Expand Down
4 changes: 1 addition & 3 deletions .core/gulp.tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ const reactium = (gulp, config, webpackConfig) => {
crossEnvBin,
'NODE_ENV=development',
'nodemon',
'./.core/index.js',
'--exec',
'babel-node',
'./.core/index.mjs',
],
done,
{ stdin: 'inherit' },
Expand Down
40 changes: 24 additions & 16 deletions .core/index.js → .core/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import cookieSession from 'cookie-session';
import morgan from 'morgan';
import path from 'path';
import fs from 'fs';
import op from 'object-path';
import _ from 'underscore';
import staticGzip from 'express-static-gzip';
import chalk from 'chalk';
import globals from './server-globals.mjs';
import path from 'node:path';
import fs from 'fs-extra';
import globbyPatched from './globby-patch.js';
import router from './server/router.mjs';
import { dirname } from '@atomic-reactor/dirname';

const globby = require('./globby-patch').sync;

const globals = require('./server-globals');
const __dirname = dirname(import.meta.url);
const globby = globbyPatched.sync;

global.rootPath = path.resolve(__dirname, '..');

Expand Down Expand Up @@ -101,7 +104,7 @@ const registeredMiddleware = async () => {

const reactiumModules = Object.keys(
op.get(
require(path.resolve(process.cwd(), 'package.json')),
fs.readJsonSync(path.resolve(process.cwd(), 'package.json')),
'reactiumDependencies',
{},
),
Expand Down Expand Up @@ -170,24 +173,29 @@ const registeredMiddleware = async () => {
// default route handler
ReactiumBoot.Server.Middleware.register('router', {
name: 'router',
use: require('./server/router').default,
use: router,
order: Enums.priority.neutral,
});
};

const registeredDevMiddleware = () => {
const registeredDevMiddleware = async () => {
const { Enums } = ReactiumBoot;

// set app variables
app.set('x-powered-by', false);

// development mode
if (process.env.NODE_ENV === 'development') {
const webpack = require('webpack');
const gulpConfig = require('./gulp.config');
const webpackConfig = require('./webpack.config')(gulpConfig);
const wpMiddlware = require('webpack-dev-middleware');
const wpHotMiddlware = require('webpack-hot-middleware');
const { default: webpack } = await import('webpack');
const { default: gulpConfig } = await import('./gulp.config.js');
const { default: webpackConfigFactory } = await import(
'./webpack.config.js'
);
const webpackConfig = webpackConfigFactory(gulpConfig);
const { default: wpMiddleware } = await import('webpack-dev-middleware');
const { default: wpHotMiddleware } = await import(
'webpack-hot-middleware'
);
const publicPath = `http://localhost:${PORT}/`;

// local development overrides for webpack config
Expand All @@ -202,7 +210,7 @@ const registeredDevMiddleware = () => {

ReactiumBoot.Server.Middleware.register('webpack', {
name: 'webpack',
use: wpMiddlware(compiler, {
use: wpMiddleware(compiler, {
serverSideRender: true,
publicPath,
}),
Expand All @@ -211,7 +219,7 @@ const registeredDevMiddleware = () => {

ReactiumBoot.Server.Middleware.register('hmr', {
name: 'hmr',
use: wpHotMiddlware(compiler, {
use: wpHotMiddleware(compiler, {
reload: true,
}),
order: Enums.priority.high,
Expand Down Expand Up @@ -317,7 +325,7 @@ const startServer = async () => {
});

if (process.env.REACTIUM_TLS_MODE === 'on') {
const spdy = require('spdy');
const spdy = await import('spdy');
const options = {
key: fs.readFileSync(
op.get(
Expand Down
File renamed without changes.
22 changes: 0 additions & 22 deletions .core/sdk/reactium-boot.js

This file was deleted.

17 changes: 10 additions & 7 deletions .core/server-globals.js → .core/server-globals.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import path from 'path';
import op from 'object-path';
import _ from 'underscore';
import reactiumBootHooks from './boot-hooks';
import reactiumBootHooks from './boot-hooks.mjs';
import path from 'node:path';
import { dirname } from '@atomic-reactor/dirname';
import ReactiumBoot from '@atomic-reactor/reactium-sdk-core';

global.ReactiumBoot = ReactiumBoot;

const __dirname = dirname(import.meta.url);

global.rootPath = path.resolve(__dirname, '..');

module.exports = async () => {
const ReactiumBoot = (await import('@atomic-reactor/reactium-sdk-core'))
.default;
global.ReactiumBoot = ReactiumBoot;
export default async () => {
global.defines = {};

const defaultPort = 3030;
Expand All @@ -35,7 +38,7 @@ module.exports = async () => {

global.TLS_PORT = op.get(process.env, 'TLS_PORT', 3443);

require('./reactium.log');
await import('./reactium.log.cjs');

await reactiumBootHooks();
};
Loading