Skip to content

Commit

Permalink
fix: read package.json dependencies when getting builders/executors (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored Jun 22, 2021
1 parent 90ec7cc commit 187f1f2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
8 changes: 1 addition & 7 deletions jest.preset.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
const nxPreset = require('@nrwl/jest/preset');
module.exports = {
...nxPreset,
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
transform: {
'^.+\\.(ts|js|html)$': 'ts-jest',
},
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html'],
coverageReporters: ['html'],
transformIgnorePatterns: ['node_modules/(?!(@types)/)'],
};
1 change: 0 additions & 1 deletion libs/server/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
preset: '../../jest.preset.js',
coverageDirectory: '../../coverage/libs/server',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: { 'ts-jest': { tsConfig: '<rootDir>/tsconfig.spec.json' } },
displayName: 'server',
};
12 changes: 8 additions & 4 deletions libs/server/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
printParseErrorCode,
ParseError,
} from 'jsonc-parser';
import { getOutputChannel } from './output-channel';

export interface SchematicDefaults {
[name: string]: string;
Expand Down Expand Up @@ -147,10 +148,13 @@ function readAndParseJson(filePath: string) {
const result = parseJson(content, errors);

if (errors.length > 0) {
const { error, offset } = errors[0];
throw new Error(
`${printParseErrorCode(error)} in JSON at position ${offset}`
);
for (const { error, offset } of errors) {
getOutputChannel().appendLine(
`${printParseErrorCode(
error
)} in JSON at position ${offset} in ${filePath}`
);
}
}

return result;
Expand Down
5 changes: 0 additions & 5 deletions libs/server/src/test-setup.ts

This file was deleted.

1 change: 0 additions & 1 deletion libs/server/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"module": "commonjs",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
12 changes: 7 additions & 5 deletions libs/vscode/json-schema/src/lib/get-all-executors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ function readExecutorCollectionsFromNodeModules(
workspaceJsonPath: string,
clearPackageJsonCache: boolean
): ExecutorInfo[] {
const basedir = join(workspaceJsonPath, '..');
const basedir = dirname(workspaceJsonPath);
const nodeModulesDir = join(basedir, 'node_modules');

if (clearPackageJsonCache) {
clearJsonCache('package.json', basedir);
}

const packages: { [packageName: string]: string } =
readAndCacheJsonFile('package.json', basedir).json.devDependencies || {};
const packageJson = readAndCacheJsonFile('package.json', basedir).json;
const packages: { [packageName: string]: string } = {
...(packageJson.devDependencies || {}),
...(packageJson.dependencies || {}),
};
const executorCollections = Object.keys(packages).filter((p) => {
try {
const packageJson = readAndCacheJsonFile(
Expand Down Expand Up @@ -92,7 +94,7 @@ function getBuilderPaths(
)) {
let path = '';
if (platform() === 'win32') {
path = `file:///${join(baseDir, value.schema).replace(/\\/g, '/')}`
path = `file:///${join(baseDir, value.schema).replace(/\\/g, '/')}`;
} else {
path = join(baseDir, value.schema);
}
Expand Down

0 comments on commit 187f1f2

Please sign in to comment.