diff --git a/Dockerfile b/Dockerfile index 6b628300..0079ac36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,7 @@ RUN apk add --no-cache \ sqlite-dev \ dbus-dev -COPY build-conf/node-sums.txt . +COPY build-utils/node-sums.txt . # Install node from balena's prebuilt cache RUN curl -SLO "${NODE_LOCATION}" \ @@ -54,7 +54,8 @@ RUN npm ci --build-from-source --sqlite=/usr/lib #dev-copy=entry.sh . #dev-cmd-live=LIVEPUSH=1 ./entry.sh -COPY webpack.config.js fix-jsonstream.js hardcode-migrations.js tsconfig.json tsconfig.release.json ./ +COPY build-utils ./build-utils +COPY webpack.config.js tsconfig.json tsconfig.release.json ./ COPY src ./src COPY test ./test COPY typings ./typings diff --git a/fix-jsonstream.js b/build-utils/fix-jsonstream.js similarity index 79% rename from fix-jsonstream.js rename to build-utils/fix-jsonstream.js index 9db46d79..a5018593 100644 --- a/fix-jsonstream.js +++ b/build-utils/fix-jsonstream.js @@ -4,6 +4,6 @@ // Also, JSONStream starts a pipe between stdin and stdout if module.parent is undefined. // This pipe can fail throwing an uncaught exception, so we fake a module.parent to prevent this. // See https://github.com/dominictarr/JSONStream/issues/129 -module.exports = function (source) { - return "module.parent = {};\n" + source.toString().replace(/^#! .*\n/, '') -} +module.exports = function(source) { + return 'module.parent = {};\n' + source.toString().replace(/^#! .*\n/, ''); +}; diff --git a/build-utils/hardcode-migrations.js b/build-utils/hardcode-migrations.js new file mode 100644 index 00000000..9bd4998f --- /dev/null +++ b/build-utils/hardcode-migrations.js @@ -0,0 +1,11 @@ +// knex migrations use dynamic requires which break with webpack. +// This hack makes the migrations directory a constant so that at least we can use webpack contexts for the +// require. +module.exports = function(source) { + return source + .toString() + .replace( + 'path.join(absoluteDir, migration.file)', + `'./migrations/'+migration.file`, + ); +}; diff --git a/build-conf/node-sums.txt b/build-utils/node-sums.txt similarity index 100% rename from build-conf/node-sums.txt rename to build-utils/node-sums.txt diff --git a/hardcode-migrations.js b/hardcode-migrations.js deleted file mode 100644 index 00c25810..00000000 --- a/hardcode-migrations.js +++ /dev/null @@ -1,9 +0,0 @@ -// knex migrations use dynamic requires which break with webpack. -// This hack makes the migrations directory a constant so that at least we can use webpack contexts for the -// require. -module.exports = function (source) { - return source - .toString() - .replace(/require\(_path2\.default\.join\(_?this\._absoluteConfigDir\(\), name\)\);/g, "require('./migrations/' + name);") - .replace("require(directory + '/' + name);", "require('./migrations/' + name);") -} diff --git a/package.json b/package.json index 547794e7..197273a8 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "packagejson:copy": "cp package.json build/", "testitems:copy": "cp -r test/data build/test/", "lint:coffee": "balena-lint test/", - "lint:typescript": "balena-lint -e ts -e js --typescript src/ test/ typings/ && tsc --noEmit && tsc --noEmit --project tsconfig.js.json", + "lint:typescript": "balena-lint -e ts -e js --typescript src/ test/ typings/ build-utils/ && tsc --noEmit && tsc --noEmit --project tsconfig.js.json", "sync": "ts-node sync/sync.ts" }, "private": true, diff --git a/tsconfig.js.json b/tsconfig.js.json index 158c1cd5..ea918db3 100644 --- a/tsconfig.js.json +++ b/tsconfig.js.json @@ -4,5 +4,5 @@ "noImplicitAny": false, "checkJs": true }, - "include": ["src/**/*", "test/**/*", "typings/**/*.d.ts"] + "include": ["src/**/*", "test/**/*", "typings/**/*.d.ts", "build-utils/**/*"] } diff --git a/webpack.config.js b/webpack.config.js index 4a9b1efd..4459ec67 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -97,17 +97,18 @@ module.exports = function(env) { module: { rules: [ { - test: new RegExp( - _.escapeRegExp(path.join('knex', 'lib', 'migrate', 'index.js')) + - '$', - ), - use: require.resolve('./hardcode-migrations'), + include: [ + new RegExp( + _.escapeRegExp(path.join('knex', 'lib', 'migrate', 'sources')), + ), + ], + use: require.resolve('./build-utils/hardcode-migrations'), }, { test: new RegExp( _.escapeRegExp(path.join('JSONStream', 'index.js')) + '$', ), - use: require.resolve('./fix-jsonstream'), + use: require.resolve('./build-utils/fix-jsonstream'), }, { test: /\.coffee$/,