Skip to content

Commit

Permalink
fix(nextjs): vite workspace libs
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham committed Feb 2, 2024
1 parent a5687d0 commit f20f5e3
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 9 deletions.
80 changes: 76 additions & 4 deletions packages/next/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ describe('app', () => {

const tsConfig = readJson(tree, 'tsconfig.json');
expect(tsConfig.include).toEqual([
'**/*.ts',
'**/*.tsx',
'**/*.js',
'**/*.jsx',
'src/**/*.ts',
'src/**/*.tsx',
'src/**/*.js',
'src/**/*.jsx',
'.next/types/**/*.ts',
`dist/${name}/.next/types/**/*.ts`,
'next-env.d.ts',
Expand Down Expand Up @@ -675,6 +675,78 @@ describe('app', () => {
`
);
});

it('should scope tsconfig to the src/ project directory', async () => {
const name = uniq();

await applicationGenerator(tree, {
name,
style: 'css',
appDir: true,
rootProject: true,
projectNameAndRootFormat: 'as-provided',
src: true,
});

const tsconfigJSON = readJson(tree, `tsconfig.json`);

expect(tsconfigJSON.include).toEqual([
'src/**/*.ts',
'src/**/*.tsx',
'src/**/*.js',
'src/**/*.jsx',
'.next/types/**/*.ts',
`dist/${name}/.next/types/**/*.ts`,
'next-env.d.ts',
]);
});

it('should scope tsconfig to the app/ project directory', async () => {
const name = uniq();

await applicationGenerator(tree, {
name,
style: 'css',
appDir: true,
rootProject: true,
projectNameAndRootFormat: 'as-provided',
src: false,
});

const tsconfigJSON = readJson(tree, `tsconfig.json`);

expect(tsconfigJSON.include).toEqual([
'app/**/*.ts',
'app/**/*.tsx',
'app/**/*.js',
'app/**/*.jsx',
'.next/types/**/*.ts',
`dist/${name}/.next/types/**/*.ts`,
'next-env.d.ts',
]);
});

it('should scope tsconfig to the pages/ project directory', async () => {
const name = uniq();

await applicationGenerator(tree, {
name,
style: 'css',
appDir: false,
rootProject: true,
projectNameAndRootFormat: 'as-provided',
src: false,
});

const tsconfigJSON = readJson(tree, `tsconfig.json`);
expect(tsconfigJSON.include).toEqual([
'pages/**/*.ts',
'pages/**/*.tsx',
'pages/**/*.js',
'pages/**/*.jsx',
'next-env.d.ts',
]);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"plugins": [{ "name": "next" }]
},
"include": [
"**/*.ts",
"**/*.tsx",
"**/*.js",
"**/*.jsx",
"<%= rootPath %>**/*.ts",
"<%= rootPath %>**/*.tsx",
"<%= rootPath %>**/*.js",
"<%= rootPath %>**/*.jsx",
<% if (appDir) { %>
"<%= layoutTypeSrcPath %>",
"<%= layoutTypeDistPath %>",
<% } %>
"next-env.d.ts"
],
"exclude": ["node_modules", "jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
"exclude": ["node_modules", "jest.config.ts", "<%= rootPath %>**/*.spec.ts", "<%= rootPath %>**/*.test.ts"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@ export function createApplicationFiles(host: Tree, options: NormalizedSchema) {
options.outputPath,
'.next/types/**/*.ts'
);

// scope tsconfig to the project directory so that it doesn't include other projects/libs
const rootPath = options.rootProject
? options.src
? 'src/'
: options.appDir
? 'app/'
: 'pages/'
: '';
const templateVariables = {
...names(options.name),
...options,
dot: '.',
tmpl: '',
offsetFromRoot,
layoutTypeSrcPath,
rootPath,
layoutTypeDistPath,
rootTsConfigPath: getRelativePathToRootTsConfig(
host,
Expand Down

0 comments on commit f20f5e3

Please sign in to comment.