Skip to content

Commit

Permalink
docs(core): fix internal package dependencies so nx.dev is not affect…
Browse files Browse the repository at this point in the history
…ed by their changes (nrwl#5878)
  • Loading branch information
jaysoo authored Jun 3, 2021
1 parent d3992e9 commit 9838d2d
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 16 deletions.
1 change: 1 addition & 0 deletions .nxignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nx-dev/**/jest.config.js
1 change: 1 addition & 0 deletions nx-dev/data-access-documents/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const nxPreset = require('@nrwl/jest/preset');
module.exports = {
...nxPreset,
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
displayName: 'nx-dev-data-access-documents',
globals: {
'ts-jest': {
Expand Down
12 changes: 9 additions & 3 deletions nx-dev/data-access-documents/src/lib/documents.api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { DocumentsApi } from './documents.api';
import type { DocumentMetadata } from './documents.models';
import { join } from 'path';
import { readJsonFile } from '@nrwl/workspace';
import { appRootPath } from '@nrwl/workspace/src/utilities/app-root';
import fs from 'fs';

const archiveRootPath = join(appRootPath, 'nx-dev/nx-dev/public/documentation');
const archiveRootPath = join(
process.env.WORKSPACE_ROOT,
'nx-dev/nx-dev/public/documentation'
);
const documentsCache = new Map<string, DocumentMetadata[]>([
['latest', readJsonFile(join(archiveRootPath, 'latest', 'map.json'))],
['previous', readJsonFile(join(archiveRootPath, 'previous', 'map.json'))],
]);
const versionsData = readJsonFile(join(archiveRootPath, 'versions.json'));

function readJsonFile(f) {
return JSON.parse(fs.readFileSync(f).toString());
}

describe('DocumentsApi', () => {
const api = new DocumentsApi(versionsData, documentsCache);

Expand Down
5 changes: 2 additions & 3 deletions nx-dev/data-access-documents/src/lib/documents.utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { join } from 'path';
import { appRootPath } from '@nrwl/workspace/src/utilities/app-root';

export const archiveRootPath = join(
appRootPath,
process.env.WORKSPACE_ROOT,
'nx-dev/nx-dev/public/documentation'
);
export const previewRootPath = join(appRootPath, 'docs');
export const previewRootPath = join(process.env.WORKSPACE_ROOT, 'docs');

export function extractTitle(markdownContent: string): string | null {
return (
Expand Down
12 changes: 9 additions & 3 deletions nx-dev/data-access-documents/src/lib/menu.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ import {
DocumentsApi,
} from '@nrwl/nx-dev/data-access-documents';
import { join } from 'path';
import { appRootPath } from '@nrwl/workspace/src/utilities/app-root';
import { readJsonFile } from '@nrwl/workspace';
import * as fs from 'fs';

const archiveRootPath = join(appRootPath, 'nx-dev/nx-dev/public/documentation');
const archiveRootPath = join(
process.env.WORKSPACE_ROOT,
'nx-dev/nx-dev/public/documentation'
);
const documentsCache = new Map<string, DocumentMetadata[]>([
['latest', readJsonFile(join(archiveRootPath, 'latest', 'map.json'))],
['previous', readJsonFile(join(archiveRootPath, 'previous', 'map.json'))],
]);
const versionsData = readJsonFile(join(archiveRootPath, 'versions.json'));

function readJsonFile(f) {
return JSON.parse(fs.readFileSync(f).toString());
}

describe('MenuApi', () => {
const docsApi = new DocumentsApi(versionsData, documentsCache);
const api = new MenuApi(docsApi);
Expand Down
1 change: 1 addition & 0 deletions nx-dev/data-access-documents/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.env.WORKSPACE_ROOT = process.cwd();
2 changes: 1 addition & 1 deletion nx-dev/data-access-documents/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"outDir": "../../dist/out-tsc",
"types": []
"types": ["node"]
},
"include": ["**/*.ts"],
"exclude": ["**/*.spec.ts"]
Expand Down
9 changes: 7 additions & 2 deletions nx-dev/nx-dev/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { join } = require('path');
// nx-ignore-next-line
const withNx = require('@nrwl/next/plugins/with-nx');

module.exports = withNx({});
module.exports = withNx({
env: {
WORKSPACE_ROOT: join(__dirname, '../..'),
},
});
3 changes: 1 addition & 2 deletions nx-dev/nx-dev/pages/api/preview-asset.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { join } from 'path';
import { appRootPath } from '@nrwl/workspace/src/utilities/app-root';

import * as send from 'send';

// Repeated here since `data-access-documents` isn't available at runtime.
const previewRootPath = join(appRootPath, 'docs');
const previewRootPath = join(process.env.WORKSPACE_ROOT, 'docs');

export default function (req: NextApiRequest, res: NextApiResponse) {
return new Promise<void>((resolve) => {
Expand Down
2 changes: 2 additions & 0 deletions nx-dev/nx-dev/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const path = require('path');
// nx-ignore-next-line
const nxJson = require('@nrwl/workspace').readNxJson();
// nx-ignore-next-line
const workspaceJson = require('@nrwl/workspace').readWorkspaceJson();

function getProjectNameWithTag(projectsJson, tag) {
Expand Down
6 changes: 4 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
"tags": ["core"]
},
"nx-dev": {
"tags": ["scope:nx-dev", "type:app"]
"tags": ["scope:nx-dev", "type:app"],
"implicitDependencies": ["docs"]
},
"nx-dev-e2e": {
"tags": ["scope:nx-dev", "type:e2e"],
Expand All @@ -134,7 +135,8 @@
"nx-dev-data-access-documents": {
"tags": ["scope:nx-dev", "type:data-access"]
},
"nx-dev-feature-search": { "tags": ["scope:nx-dev", "type:feature"] }
"nx-dev-feature-search": { "tags": ["scope:nx-dev", "type:feature"] },
"docs": { "tags": ["scope:nx-dev"] }
},
"affected": { "defaultBase": "master" }
}
5 changes: 5 additions & 0 deletions workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,11 @@
}
}
}
},
"docs": {
"root": "docs",
"sourceRoot": "docs",
"projectType": "library"
}
},
"cli": {
Expand Down

0 comments on commit 9838d2d

Please sign in to comment.