Skip to content

Commit

Permalink
fix(builds): fix GCP and AWS builds
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Mar 30, 2020
1 parent 0b20a68 commit 3aa8473
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/whook-aws-lambda/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function prepareBuildEnvironment(
$.register(
constant('INITIALIZER_PATH_MAP', {
ENV: require.resolve('@whook/whook/dist/services/ProxyedENV'),
log: require.resolve('@whook/aws-lambda/services/log'),
log: require.resolve(__dirname + '/services/log'),
time: require.resolve('common-services/dist/time'),
delay: require.resolve('common-services/dist/delay'),
}),
Expand Down
15 changes: 9 additions & 6 deletions packages/whook-aws-lambda/src/services/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type WhookCompilerOptions = {
externalModules?: string[];
ignoredModules?: string[];
extensions?: string[];
target?: string;
};
export type WhookCompilerConfig = {
NODE_ENV?: string;
Expand All @@ -28,10 +29,11 @@ export type WhookCompilerService = (
entryPoint: string,
) => Promise<WhookCompilationResult>;

export const DEFAULT_COMPILER_OPTIONS: WhookCompilerOptions = {
export const DEFAULT_COMPILER_OPTIONS: Required<WhookCompilerOptions> = {
externalModules: ['ecstatic'],
ignoredModules: [],
extensions: ['.ts', '.js', '.json'],
target: '12.13',
};

async function initCompiler({
Expand All @@ -46,7 +48,8 @@ async function initCompiler({
): Promise<WhookCompilationResult> {
const debugging = DEBUG_NODE_ENVS.includes(NODE_ENV);
const basePath = path.dirname(entryPoint);
const compilerOptions: WhookCompilerOptions = {
const compilerOptions: Required<WhookCompilerOptions> = {
...DEFAULT_COMPILER_OPTIONS,
...COMPILER_OPTIONS,
...options,
};
Expand Down Expand Up @@ -112,7 +115,7 @@ async function initCompiler({
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
...(compilerOptions.ignoredModules || []).map(
...compilerOptions.ignoredModules.map(
ignoredModule => new webpack.IgnorePlugin(new RegExp(ignoredModule)),
),
...(debugging
Expand All @@ -126,9 +129,9 @@ async function initCompiler({
__dirname: true,
},
resolve: {
extensions: compilerOptions.extensions || ['.js'],
extensions: compilerOptions.extensions,
},
externals: compilerOptions.externalModules || [],
externals: compilerOptions.externalModules,
module: {
rules: [
// This rule must be added to handle deep dependencies usage
Expand All @@ -151,7 +154,7 @@ async function initCompiler({
{
modules: false,
targets: {
node: '12.13',
node: compilerOptions.target,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/whook-gcp-functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function prepareBuildEnvironment(
$.register(
constant('INITIALIZER_PATH_MAP', {
ENV: require.resolve('@whook/whook/dist/services/ProxyedENV'),
log: require.resolve('@whook/gcp-functions/services/log'),
log: require.resolve(__dirname + '/services/log'),
time: require.resolve('common-services/dist/time'),
delay: require.resolve('common-services/dist/delay'),
}),
Expand Down
13 changes: 8 additions & 5 deletions packages/whook-gcp-functions/src/services/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type WhookCompilerOptions = {
externalModules?: string[];
ignoredModules?: string[];
extensions?: string[];
target?: string;
};
export type WhookCompilerConfig = {
NODE_ENV?: string;
Expand All @@ -28,10 +29,11 @@ export type WhookCompilerService = (
entryPoint: string,
) => Promise<WhookCompilationResult>;

export const DEFAULT_COMPILER_OPTIONS: WhookCompilerOptions = {
export const DEFAULT_COMPILER_OPTIONS: Required<WhookCompilerOptions> = {
externalModules: ['ecstatic'],
ignoredModules: [],
extensions: ['.ts', '.js', '.json'],
target: '10.16.2',
};

async function initCompiler({
Expand All @@ -47,6 +49,7 @@ async function initCompiler({
const debugging = DEBUG_NODE_ENVS.includes(NODE_ENV);
const basePath = path.dirname(entryPoint);
const compilerOptions: WhookCompilerOptions = {
...DEFAULT_COMPILER_OPTIONS,
...COMPILER_OPTIONS,
...options,
};
Expand Down Expand Up @@ -112,7 +115,7 @@ async function initCompiler({
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
...(compilerOptions.ignoredModules || []).map(
...compilerOptions.ignoredModules.map(
ignoredModule => new webpack.IgnorePlugin(new RegExp(ignoredModule)),
),
...(debugging
Expand All @@ -126,9 +129,9 @@ async function initCompiler({
__dirname: true,
},
resolve: {
extensions: compilerOptions.extensions || ['.js'],
extensions: compilerOptions.extensions,
},
externals: compilerOptions.externalModules || [],
externals: compilerOptions.externalModules,
module: {
rules: [
// This rule must be added to handle deep dependencies usage
Expand All @@ -151,7 +154,7 @@ async function initCompiler({
{
modules: false,
targets: {
node: '12.13',
node: compilerOptions.target,
},
},
],
Expand Down

0 comments on commit 3aa8473

Please sign in to comment.