diff --git a/.eslintrc b/.eslintrc index 06e385d6c3..60f818dc24 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,6 +4,7 @@ "es6": true, "node": true }, + "ignorePatterns": ["./shared"], "extends": ["eslint:recommended", "plugin:prettier/recommended"], "globals": { "Atomics": "readonly", diff --git a/jest.config.js b/jest.config.js index 570da92d1c..318be04bf9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -24,5 +24,8 @@ module.exports = { isolatedModules: true, }, }, + moduleNameMapper: { + '^~shared(.*)$': '/shared$1', + }, setupFilesAfterEnv: ['jest-extended'], } diff --git a/package-lock.json b/package-lock.json index ad8cc6a7cf..806665b071 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18175,6 +18175,11 @@ "integrity": "sha512-KP+rweeXjP5P1SMoBQTS7NQG4xIZLbrlJ24dKDjuRRX3kzn+pCAg4w1e+Er6UQEoBtqjbXDM9PTbQkXUk4S7iw==", "dev": true }, + "module-alias": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz", + "integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==" + }, "module-not-found-error": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/module-not-found-error/-/module-not-found-error-1.0.1.tgz", diff --git a/package.json b/package.json index 49cd182067..4b4b055052 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", @@ -254,5 +255,8 @@ "webpack-cli": "^3.3.12", "webpack-merge": "^4.1.3", "worker-loader": "^2.0.0" + }, + "_moduleAliases": { + "~shared": "build/shared" } } diff --git a/tests/end-to-end/helpers/selectors.js b/tests/end-to-end/helpers/selectors.js index 39373c3236..c6d155ee31 100644 --- a/tests/end-to-end/helpers/selectors.js +++ b/tests/end-to-end/helpers/selectors.js @@ -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'), diff --git a/tests/end-to-end/helpers/util.js b/tests/end-to-end/helpers/util.js index 38175b99d7..9217d68c97 100644 --- a/tests/end-to-end/helpers/util.js +++ b/tests/end-to-end/helpers/util.js @@ -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) @@ -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) } } diff --git a/tests/unit/frontend/jest.config.js b/tests/unit/frontend/jest.config.js index 6294e2c5aa..f559b74c65 100644 --- a/tests/unit/frontend/jest.config.js +++ b/tests/unit/frontend/jest.config.js @@ -11,6 +11,9 @@ module.exports = { isolatedModules: true, }, }, + moduleNameMapper: { + '^~shared(.*)$': '/shared$1', + }, clearMocks: true, setupFilesAfterEnv: ['jest-extended'], setupFiles: ['jest-localstorage-mock'], diff --git a/tsconfig.json b/tsconfig.json index faf3c9d613..26974efd9e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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 */ @@ -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. */ @@ -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"], } diff --git a/webpack.common.js b/webpack.common.js index c5dfee45f2..4a434e6004 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -42,6 +42,7 @@ module.exports = [ resolve: { alias: { shared: path.resolve(__dirname, 'src/shared/'), + '~shared': path.resolve(__dirname, 'shared/'), }, extensions: ['.ts', '.js'], },