Skip to content

Commit

Permalink
Revert "feat(core): use the native hasher by default (nrwl#15071)"
Browse files Browse the repository at this point in the history
This reverts commit 7d80f25.
  • Loading branch information
FrozenPandaz committed Feb 24, 2023
1 parent 892dbe8 commit e0d69b4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 114 deletions.
11 changes: 5 additions & 6 deletions packages/nx/src/hasher/file-hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import { join } from 'path';
import { NativeFileHasher } from './native-file-hasher';

function createFileHasher(): FileHasherBase {
// special case for unit tests
if (workspaceRoot === '/root') {
return new NodeBasedFileHasher();
}
try {
if (
!(
process.env.NX_NON_NATIVE_HASHER &&
process.env.NX_NON_NATIVE_HASHER == 'false'
)
) {
if (process.env.NX_NATIVE_HASHER) {
return new NativeFileHasher();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { TempFs } from '../../utils/testing/temp-fs';
const tempFs = new TempFs('explicit-package-json');

import '../../utils/testing/mock-fs';
import { buildExplicitPackageJsonDependencies } from './explicit-package-json-dependencies';

import { vol } from 'memfs';
import { createProjectFileMap } from '../file-map-utils';
import { defaultFileHasher } from '../../hasher/file-hasher';
import {
Expand All @@ -11,11 +9,15 @@ import {
} from '../../config/project-graph';
import { ProjectGraphBuilder } from '../project-graph-builder';

jest.mock('nx/src/utils/workspace-root', () => ({
workspaceRoot: '/root',
}));

describe('explicit package json dependencies', () => {
let ctx: ProjectGraphProcessorContext;
let projects: Record<string, ProjectGraphProjectNode>;

beforeEach(async () => {
let fsJson;
beforeEach(() => {
const projectsConfigurations = {
projects: {
proj: {
Expand All @@ -37,12 +39,12 @@ describe('explicit package json dependencies', () => {
npmScope: 'proj',
};

await tempFs.createFiles({
fsJson = {
'./package.json': `{
"name": "test",
"dependencies": [],
"devDependencies": []
}`,
"name": "test",
"dependencies": [],
"devDependencies": []
}`,
'./nx.json': JSON.stringify(nxJsonConfiguration),
'./tsconfig.base.json': JSON.stringify({}),
'./libs/proj2/package.json': JSON.stringify({ name: 'proj2' }),
Expand All @@ -51,9 +53,10 @@ describe('explicit package json dependencies', () => {
dependencies: { proj2: '*', external: '12.0.0' },
devDependencies: { proj3: '*' },
}),
});
};
vol.fromJSON(fsJson, '/root');

await defaultFileHasher.init();
defaultFileHasher.init();

ctx = {
projectsConfigurations,
Expand Down Expand Up @@ -86,10 +89,6 @@ describe('explicit package json dependencies', () => {
};
});

afterEach(() => {
tempFs.cleanup();
});

it(`should add dependencies for projects based on deps in package.json`, () => {
const builder = new ProjectGraphBuilder();
Object.values(projects).forEach((p) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { TempFs } from '../../utils/testing/temp-fs';
const tempFs = new TempFs('explicit-project-deps');

import '../../utils/testing/mock-fs';
import { vol } from 'memfs';
import { defaultFileHasher } from '../../hasher/file-hasher';
import { createProjectFileMap } from '../file-map-utils';
import { ProjectGraphBuilder } from '../project-graph-builder';
import { buildExplicitTypeScriptDependencies } from './explicit-project-dependencies';

jest.mock('nx/src/utils/workspace-root', () => ({
workspaceRoot: '/root',
}));

// projectName => tsconfig import path
const dependencyProjectNamesToImportPaths = {
proj2: '@proj/my-second-proj',
Expand All @@ -15,13 +18,13 @@ const dependencyProjectNamesToImportPaths = {

describe('explicit project dependencies', () => {
beforeEach(() => {
tempFs.reset();
vol.reset();
});

describe('static imports, dynamic imports, and commonjs requires', () => {
it('should build explicit dependencies for static imports, and top-level dynamic imports and commonjs requires', async () => {
it('should build explicit dependencies for static imports, and top-level dynamic imports and commonjs requires', () => {
const sourceProjectName = 'proj';
const { ctx, builder } = await createVirtualWorkspace({
const { ctx, builder } = createVirtualWorkspace({
sourceProjectName,
sourceProjectFiles: [
{
Expand Down Expand Up @@ -69,9 +72,9 @@ describe('explicit project dependencies', () => {
]);
});

it('should build explicit dependencies for static exports', async () => {
it('should build explicit dependencies for static exports', () => {
const sourceProjectName = 'proj';
const { ctx, builder } = await createVirtualWorkspace({
const { ctx, builder } = createVirtualWorkspace({
sourceProjectName,
sourceProjectFiles: [
{
Expand Down Expand Up @@ -112,9 +115,9 @@ describe('explicit project dependencies', () => {
]);
});

it(`should build explicit dependencies for TypeScript's import/export require syntax, and side-effectful import`, async () => {
it(`should build explicit dependencies for TypeScript's import/export require syntax, and side-effectful import`, () => {
const sourceProjectName = 'proj';
const { ctx, builder } = await createVirtualWorkspace({
const { ctx, builder } = createVirtualWorkspace({
sourceProjectName,
sourceProjectFiles: [
{
Expand Down Expand Up @@ -155,9 +158,9 @@ describe('explicit project dependencies', () => {
]);
});

it('should build explicit dependencies for nested dynamic imports and commonjs requires', async () => {
it('should build explicit dependencies for nested dynamic imports and commonjs requires', () => {
const sourceProjectName = 'proj';
const { ctx, builder } = await createVirtualWorkspace({
const { ctx, builder } = createVirtualWorkspace({
sourceProjectName,
sourceProjectFiles: [
{
Expand Down Expand Up @@ -219,9 +222,9 @@ describe('explicit project dependencies', () => {
]);
});

it('should build explicit dependencies when relative paths are used', async () => {
it('should build explicit dependencies when relative paths are used', () => {
const sourceProjectName = 'proj';
const { ctx, builder } = await createVirtualWorkspace({
const { ctx, builder } = createVirtualWorkspace({
sourceProjectName,
sourceProjectFiles: [
{
Expand Down Expand Up @@ -260,9 +263,9 @@ describe('explicit project dependencies', () => {
]);
});

it('should not build explicit dependencies when nx-ignore-next-line comments are present', async () => {
it('should not build explicit dependencies when nx-ignore-next-line comments are present', () => {
const sourceProjectName = 'proj';
const { ctx, builder } = await createVirtualWorkspace({
const { ctx, builder } = createVirtualWorkspace({
sourceProjectName,
sourceProjectFiles: [
{
Expand Down Expand Up @@ -352,9 +355,9 @@ describe('explicit project dependencies', () => {
expect(res).toEqual([]);
});

it('should not build explicit dependencies for stringified or templatized import/require statements', async () => {
it('should not build explicit dependencies for stringified or templatized import/require statements', () => {
const sourceProjectName = 'proj';
const { ctx, builder } = await createVirtualWorkspace({
const { ctx, builder } = createVirtualWorkspace({
sourceProjectName,
sourceProjectFiles: [
{
Expand Down Expand Up @@ -435,9 +438,9 @@ describe('explicit project dependencies', () => {
* https://angular.io/guide/deprecations#loadchildren-string-syntax
*/
describe('legacy Angular loadChildren string syntax', () => {
it('should build explicit dependencies for legacy Angular loadChildren string syntax', async () => {
it('should build explicit dependencies for legacy Angular loadChildren string syntax', () => {
const sourceProjectName = 'proj';
const { ctx, builder } = await createVirtualWorkspace({
const { ctx, builder } = createVirtualWorkspace({
sourceProjectName,
sourceProjectFiles: [
{
Expand Down Expand Up @@ -490,9 +493,9 @@ describe('explicit project dependencies', () => {
]);
});

it('should not build explicit dependencies when nx-ignore-next-line comments are present', async () => {
it('should not build explicit dependencies when nx-ignore-next-line comments are present', () => {
const sourceProjectName = 'proj';
const { ctx, builder } = await createVirtualWorkspace({
const { ctx, builder } = createVirtualWorkspace({
sourceProjectName,
sourceProjectFiles: [
{
Expand Down Expand Up @@ -558,7 +561,7 @@ interface VirtualWorkspaceConfig {
* Prepares a minimal workspace and virtual file-system for the given files and dependency
* projects in order to be able to execute `buildExplicitTypeScriptDependencies()` in the tests.
*/
async function createVirtualWorkspace(config: VirtualWorkspaceConfig) {
function createVirtualWorkspace(config: VirtualWorkspaceConfig) {
const nxJson = {
npmScope: 'proj',
};
Expand Down Expand Up @@ -639,9 +642,9 @@ async function createVirtualWorkspace(config: VirtualWorkspaceConfig) {

fsJson['./tsconfig.base.json'] = JSON.stringify(tsConfig);

await tempFs.createFiles(fsJson);
vol.fromJSON(fsJson, '/root');

await defaultFileHasher.init();
defaultFileHasher.init();

return {
ctx: {
Expand Down
28 changes: 19 additions & 9 deletions packages/nx/src/project-graph/build-project-graph.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { TempFs } from '../utils/testing/temp-fs';
const tempFs = new TempFs('explicit-package-json');
import '../utils/testing/mock-fs';

import { vol, fs } from 'memfs';

jest.mock('nx/src/utils/workspace-root', () => ({
workspaceRoot: '/root',
}));
import { buildProjectGraph } from './build-project-graph';
import * as fastGlob from 'fast-glob';
import { defaultFileHasher } from '../hasher/file-hasher';
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
import { NxJsonConfiguration } from '../config/nx-json';
import { stripIndents } from '../utils/strip-indents';
import { DependencyType } from '../config/project-graph';

describe('project graph', () => {
let packageJson: any;
let packageLockJson: any;
let projects: ProjectsConfigurations;
let nxJson: NxJsonConfiguration;
let tsConfigJson: any;
let filesJson: any;
Expand Down Expand Up @@ -184,8 +190,8 @@ describe('project graph', () => {
'./apps/api/project.json': JSON.stringify(apiProjectJson),
};

tempFs.reset();
await tempFs.createFiles(filesJson);
vol.reset();
vol.fromJSON(filesJson, '/root');
await defaultFileHasher.init();

const globResults = [
Expand All @@ -202,13 +208,17 @@ describe('project graph', () => {
});

it('should throw an appropriate error for an invalid json config', async () => {
tempFs.appendFile('tsconfig.base.json', 'invalid');
vol.appendFileSync('/root/tsconfig.base.json', 'invalid');
try {
await buildProjectGraph();
fail('Invalid tsconfigs should cause project graph to throw error');
} catch (e) {
expect(e.message).toContain(`${tempFs.tempDir}/tsconfig.base.json`);
expect(e.message).toContain(`invalid`);
expect(e.message).toMatchInlineSnapshot(`
"InvalidSymbol in /root/tsconfig.base.json at 1:248
> 1 | {\\"compilerOptions\\":{\\"baseUrl\\":\\".\\",\\"paths\\":{\\"@nrwl/shared/util\\":[\\"libs/shared/util/src/index.ts\\"],\\"@nrwl/shared-util-data\\":[\\"libs/shared/util/data/src/index.ts\\"],\\"@nrwl/ui\\":[\\"libs/ui/src/index.ts\\"],\\"@nrwl/lazy-lib\\":[\\"libs/lazy-lib/src/index.ts\\"]}}}invalid
  |  ^^^^^^^
"
`);
}
});

Expand Down Expand Up @@ -274,8 +284,8 @@ describe('project graph', () => {
});

it('should handle circular dependencies', async () => {
tempFs.writeFile(
'libs/shared/util/src/index.ts',
fs.writeFileSync(
'/root/libs/shared/util/src/index.ts',
`import * as ui from '@nrwl/ui';`
);

Expand Down
57 changes: 0 additions & 57 deletions packages/nx/src/utils/testing/temp-fs.ts

This file was deleted.

0 comments on commit e0d69b4

Please sign in to comment.