Skip to content

Commit

Permalink
build: set up tooling to handle new shared root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui committed Jul 6, 2021
1 parent ca3cdc9 commit 089eee5
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"es6": true,
"node": true
},
"ignorePatterns": ["./shared"],
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"globals": {
"Atomics": "readonly",
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ module.exports = {
isolatedModules: true,
},
},
moduleNameMapper: {
'^~shared(.*)$': '<rootDir>/shared$1',
},
setupFilesAfterEnv: ['jest-extended'],
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"test-backend:watch": "env-cmd -f tests/.test-env jest --watch",
"test-frontend": "jest --config=tests/unit/frontend/jest.config.js",
"build": "npm run build-backend && npm run build-frontend",
"build-backend": "tsc -p tsconfig.build.json",
"build-backend": "tsc -b tsconfig.build.json",
"build-frontend": "webpack --config webpack.prod.js",
"build-frontend-dev": "webpack --config webpack.dev.js",
"build-frontend-dev:watch": "webpack --config webpack.dev.js --watch",
"start": "node -r dotenv/config dist/backend/app/server.js",
"start": "node -r dotenv/config dist/backend/src/app/server.js",
"dev": "docker-compose up --build",
"docker-dev": "npm run build-frontend-dev:watch & ts-node-dev --respawn --transpile-only --inspect=0.0.0.0 --exit-child -r dotenv/config -- src/app/server.ts",
"test": "npm run test-backend && npm run test-frontend",
Expand All @@ -33,7 +33,7 @@
"test-e2e-build": "npm run build-backend && npm run build-frontend-dev",
"test-e2e-ci": "env-cmd -f tests/.test-env --use-shell \"npm run download-binary && npm run testcafe-command\"",
"testcafe-command": "testcafe --skip-js-errors -c 3 chrome:headless ./tests/end-to-end --app \"npm run test-e2e-server\" --app-init-delay 10000",
"test-e2e-server": "concurrently --success last --kill-others \"mockpass\" \"maildev\" \"node dist/backend/app/server.js\" \"node ./tests/mock-webhook-server.js\"",
"test-e2e-server": "concurrently --success last --kill-others \"mockpass\" \"maildev\" \"node dist/backend/src/app/server.js\" \"node ./tests/mock-webhook-server.js\"",
"lint-code": "eslint src/ --quiet --fix",
"lint-style": "stylelint '*/**/*.css' --quiet --fix",
"lint-html": "htmlhint && prettier --write './src/public/**/*.html' --ignore-path './dist/**' --loglevel silent",
Expand Down Expand Up @@ -122,6 +122,7 @@
"jwt-decode": "^3.1.2",
"libphonenumber-js": "^1.9.21",
"lodash": "^4.17.21",
"module-alias": "^2.2.2",
"moment-timezone": "0.5.33",
"mongodb-uri": "^0.9.7",
"mongoose": "^5.12.13",
Expand Down Expand Up @@ -254,5 +255,8 @@
"webpack-cli": "^3.3.12",
"webpack-merge": "^4.1.3",
"worker-loader": "^2.0.0"
},
"_moduleAliases": {
"~shared": "build/shared"
}
}
4 changes: 2 additions & 2 deletions tests/end-to-end/helpers/selectors.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { Selector } = require('testcafe')
const {
types: basicTypes,
} = require('../../../dist/backend/shared/resources/basic')
} = require('../../../dist/backend/src/shared/resources/basic')
const {
types: myInfoTypes,
} = require('../../../dist/backend/shared/resources/myinfo')
} = require('../../../dist/backend/src/shared/resources/myinfo')

const landingPage = {
tagline: Selector('#tagline'),
Expand Down
8 changes: 4 additions & 4 deletions tests/end-to-end/helpers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ const {
mockpass,
} = require('./selectors')

const { types } = require('../../../dist/backend/shared/resources/basic')
const { types } = require('../../../dist/backend/src/shared/resources/basic')

const {
SPCPFieldTitle,
} = require('../../../dist/backend/types/field/fieldTypes')
} = require('../../../dist/backend/src/types/field/fieldTypes')

const NON_SUBMITTED_FIELDS = types
.filter((field) => !field.submitted)
Expand Down Expand Up @@ -248,9 +248,9 @@ function makeModel(db, modelFilename, modelName) {
// Need this try catch block as some schemas may have been converted to
// TypeScript and use default exports instead.
try {
return spec(`dist/backend/app/models/${modelFilename}`)(db)
return spec(`dist/backend/src/app/models/${modelFilename}`)(db)
} catch (e) {
return spec(`dist/backend/app/models/${modelFilename}`).default(db)
return spec(`dist/backend/src/app/models/${modelFilename}`).default(db)
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/unit/frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module.exports = {
isolatedModules: true,
},
},
moduleNameMapper: {
'^~shared(.*)$': '<rootDir>/shared$1',
},
clearMocks: true,
setupFilesAfterEnv: ['jest-extended'],
setupFiles: ['jest-localstorage-mock'],
Expand Down
14 changes: 11 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// prettier-ignore
// This config is the base config used for compilation and IDE support
{
"references": [
{ "path": "shared" }
],
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

Expand Down Expand Up @@ -45,8 +48,13 @@
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": ".", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
"paths": {
"~shared/*": ["shared/*"]
}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
"rootDirs": [
"src",
"shared"
], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
Expand All @@ -68,5 +76,5 @@
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": ["src", "tests"],
"include": ["src", "tests", "shared"],
}
1 change: 1 addition & 0 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = [
resolve: {
alias: {
shared: path.resolve(__dirname, 'src/shared/'),
'~shared': path.resolve(__dirname, 'shared/'),
},
extensions: ['.ts', '.js'],
},
Expand Down

0 comments on commit 089eee5

Please sign in to comment.