-
Notifications
You must be signed in to change notification settings - Fork 1.5k
build(cli): integrate nx #16648
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
build(cli): integrate nx #16648
Changes from 1 commit
c61d4a8
537d6d7
a72cd0e
17675f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"name": "cli", | ||
"projectType": "application", | ||
"sourceRoot": "apps/cli/src", | ||
"tags": ["scope:cli", "type:app"], | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/webpack:webpack", | ||
"outputs": ["{options.outputPath}"], | ||
"defaultConfiguration": "oss-dev", | ||
"options": { | ||
"outputPath": "dist/apps/cli", | ||
"webpackConfig": "apps/cli/webpack.config.js", | ||
"tsConfig": "apps/cli/tsconfig.json", | ||
"main": "apps/cli/src/bw.ts", | ||
"target": "node", | ||
"compiler": "tsc" | ||
}, | ||
"configurations": { | ||
"oss": { | ||
"mode": "production", | ||
"outputPath": "dist/apps/cli/oss" | ||
}, | ||
"oss-dev": { | ||
"mode": "development", | ||
"outputPath": "dist/apps/cli/oss-dev" | ||
}, | ||
"bit": { | ||
"mode": "production", | ||
"outputPath": "dist/apps/cli/bit", | ||
"webpackConfig": "bitwarden_license/bit-cli/webpack.config.js", | ||
"main": "bitwarden_license/bit-cli/src/bw.ts", | ||
"tsConfig": "bitwarden_license/bit-cli/tsconfig.json" | ||
}, | ||
"bit-dev": { | ||
"mode": "development", | ||
"outputPath": "dist/apps/cli/bit-dev", | ||
"webpackConfig": "bitwarden_license/bit-cli/webpack.config.js", | ||
"main": "bitwarden_license/bit-cli/src/bw.ts", | ||
"tsConfig": "bitwarden_license/bit-cli/tsconfig.json" | ||
} | ||
} | ||
}, | ||
"serve": { | ||
"executor": "@nx/webpack:webpack", | ||
"defaultConfiguration": "oss-dev", | ||
"options": { | ||
"outputPath": "dist/apps/cli", | ||
"webpackConfig": "apps/cli/webpack.config.js", | ||
"tsConfig": "apps/cli/tsconfig.json", | ||
"main": "apps/cli/src/bw.ts", | ||
"target": "node", | ||
"compiler": "tsc", | ||
"watch": true | ||
}, | ||
"configurations": { | ||
"oss-dev": { | ||
"mode": "development", | ||
"outputPath": "dist/apps/cli/oss-dev" | ||
}, | ||
"bit-dev": { | ||
"mode": "development", | ||
"outputPath": "dist/apps/cli/bit-dev", | ||
"webpackConfig": "bitwarden_license/bit-cli/webpack.config.js", | ||
"main": "bitwarden_license/bit-cli/src/bw.ts", | ||
"tsConfig": "bitwarden_license/bit-cli/tsconfig.json" | ||
} | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "apps/cli/jest.config.js" | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["apps/cli/**/*.ts"] | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: instead of putting the default values interspersed in the code patterns: [{ from: params.localesPath || "./src/locales", to: "locales" }], could we move it all to one place? const DEFAULT_PARAMS = {
outputPath: "...",
mode: "...",
env: "...",
modulesPath: [],
localesPath: "...",
externalsModulesDir: "...",
watch: "...",
};
module.exports.buildConfig = function buildConfig(params) {
params = { ...DEFAULT_PARAMS, params }; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Really cleans this up a lot. Implemented as suggested on a72cd0e. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,48 @@ | ||
const path = require("path"); | ||
const { buildConfig } = require("./webpack.base"); | ||
|
||
module.exports = buildConfig({ | ||
configName: "OSS", | ||
entry: "./src/bw.ts", | ||
tsConfig: "./tsconfig.json", | ||
}); | ||
module.exports = (webpackConfig, context) => { | ||
// Detect if called by Nx (context parameter exists) | ||
const isNxBuild = context && context.options; | ||
|
||
if (isNxBuild) { | ||
// Nx build configuration | ||
const mode = context.options.mode || "development"; | ||
if (process.env.NODE_ENV == null) { | ||
process.env.NODE_ENV = mode; | ||
} | ||
const ENV = (process.env.ENV = process.env.NODE_ENV); | ||
|
||
return buildConfig({ | ||
configName: "OSS", | ||
entry: context.options.main || "apps/cli/src/bw.ts", | ||
tsConfig: "tsconfig.base.json", | ||
outputPath: path.resolve(context.context.root, context.options.outputPath), | ||
mode: mode, | ||
env: ENV, | ||
modulesPath: [path.resolve("node_modules")], | ||
localesPath: "apps/cli/src/locales", | ||
externalsModulesDir: "node_modules", | ||
watch: context.options.watch || false, | ||
}); | ||
} else { | ||
// npm build configuration | ||
if (process.env.NODE_ENV == null) { | ||
process.env.NODE_ENV = "development"; | ||
} | ||
const ENV = (process.env.ENV = process.env.NODE_ENV); | ||
const mode = ENV; | ||
|
||
return buildConfig({ | ||
configName: "OSS", | ||
entry: "./src/bw.ts", | ||
tsConfig: "./tsconfig.json", | ||
outputPath: path.resolve(__dirname, "build"), | ||
mode: mode, | ||
env: ENV, | ||
modulesPath: [path.resolve("../../node_modules")], | ||
localesPath: "./src/locales", | ||
externalsModulesDir: "../../node_modules", | ||
}); | ||
Comment on lines
+36
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of these are the default values in webpack.base, but they won't be for long so I was verbose with these args. |
||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,48 @@ | ||
const path = require("path"); | ||
const { buildConfig } = require("../../apps/cli/webpack.base"); | ||
|
||
module.exports = buildConfig({ | ||
configName: "Commercial", | ||
entry: "../../bitwarden_license/bit-cli/src/bw.ts", | ||
tsConfig: "../../bitwarden_license/bit-cli/tsconfig.json", | ||
}); | ||
module.exports = (webpackConfig, context) => { | ||
// Detect if called by Nx (context parameter exists) | ||
const isNxBuild = context && context.options; | ||
|
||
if (isNxBuild) { | ||
// Nx build configuration | ||
const mode = context.options.mode || "development"; | ||
if (process.env.NODE_ENV == null) { | ||
process.env.NODE_ENV = mode; | ||
} | ||
const ENV = (process.env.ENV = process.env.NODE_ENV); | ||
|
||
return buildConfig({ | ||
configName: "Commercial", | ||
entry: context.options.main || "bitwarden_license/bit-cli/src/bw.ts", | ||
tsConfig: "tsconfig.base.json", | ||
outputPath: path.resolve(context.context.root, context.options.outputPath), | ||
mode: mode, | ||
env: ENV, | ||
modulesPath: [path.resolve("node_modules")], | ||
localesPath: "apps/cli/src/locales", | ||
externalsModulesDir: "node_modules", | ||
watch: context.options.watch || false, | ||
}); | ||
} else { | ||
// npm build configuration | ||
if (process.env.NODE_ENV == null) { | ||
process.env.NODE_ENV = "development"; | ||
} | ||
const ENV = (process.env.ENV = process.env.NODE_ENV); | ||
const mode = ENV; | ||
|
||
return buildConfig({ | ||
configName: "Commercial", | ||
entry: "../../bitwarden_license/bit-cli/src/bw.ts", | ||
tsConfig: "../../bitwarden_license/bit-cli/tsconfig.json", | ||
outputPath: path.resolve(__dirname, "../../apps/cli/build"), | ||
mode: mode, | ||
env: ENV, | ||
modulesPath: [path.resolve("../../node_modules")], | ||
localesPath: "../../apps/cli/src/locales", | ||
externalsModulesDir: "../../node_modules", | ||
}); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question/suggestion: should we take this as an opportunity to stop using
bit
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented as suggested on 537d6d7
I'm going to get a task in Jira for the next Nx focused epic to rename the folders themselves whenever we remove the old npm scripts. No ticket for that right this second but I'm talking to Todd about it.
Screenshot of a "commercial" build passing: