Skip to content

Commit

Permalink
chore(misc): address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Dec 12, 2024
1 parent 3a15f57 commit b9b388b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 33 deletions.
44 changes: 44 additions & 0 deletions packages/node/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,5 +633,49 @@ describe('lib', () => {
}
`);
});

it('should set correct options for swc', async () => {
await libraryGenerator(tree, {
directory: 'mylib',
buildable: true,
compiler: 'swc',
unitTestRunner: 'jest',
addPlugin: true,
} as Schema);

expect(readJson(tree, 'mylib/package.json')).toMatchInlineSnapshot(`
{
"dependencies": {
"tslib": "^2.3.0",
},
"main": "./dist/index.js",
"name": "@proj/mylib",
"nx": {
"name": "mylib",
"projectType": "library",
"sourceRoot": "mylib/src",
"targets": {
"build": {
"executor": "@nx/js:swc",
"options": {
"main": "mylib/src/index.ts",
"outputPath": "mylib/dist",
"packageJson": "mylib/package.json",
"stripLeadingPaths": true,
"tsConfig": "mylib/tsconfig.lib.json",
},
"outputs": [
"{options.outputPath}",
],
},
},
},
"private": true,
"type": "commonjs",
"typings": "./dist/index.d.ts",
"version": "0.0.1",
}
`);
});
});
});
15 changes: 10 additions & 5 deletions packages/node/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,19 @@ function updateProject(tree: Tree, options: NormalizedSchema) {
executor: `@nx/js:${options.compiler}`,
outputs: ['{options.outputPath}'],
options: {
outputPath: joinPathFragments(
'dist',
rootProject ? options.projectName : options.projectRoot
),
outputPath: options.isUsingTsSolutionConfig
? joinPathFragments(options.projectRoot, 'dist')
: joinPathFragments(
'dist',
rootProject ? options.projectName : options.projectRoot
),
tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
packageJson: `${options.projectRoot}/package.json`,
main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
assets: [`${options.projectRoot}/*.md`],
assets: options.isUsingTsSolutionConfig
? undefined
: [`${options.projectRoot}/*.md`],
stripLeadingPaths: options.isUsingTsSolutionConfig ? true : undefined,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ exports[`app generated files content - as-provided - my-app general application

exports[`app generated files content - as-provided - my-app general application should configure tsconfig and project.json correctly 2`] = `
"{
"compilerOptions": {},
"files": [],
"include": [".nuxt/nuxt.d.ts"],
"references": [
Expand Down Expand Up @@ -190,7 +189,6 @@ exports[`app generated files content - as-provided - my-app general application

exports[`app generated files content - as-provided - my-app general application should configure vitest correctly 3`] = `
"{
"compilerOptions": {},
"files": [],
"include": [".nuxt/nuxt.d.ts"],
"references": [
Expand Down Expand Up @@ -469,7 +467,6 @@ exports[`app generated files content - as-provided - myApp general application s

exports[`app generated files content - as-provided - myApp general application should configure tsconfig and project.json correctly 2`] = `
"{
"compilerOptions": {},
"files": [],
"include": [".nuxt/nuxt.d.ts"],
"references": [
Expand Down Expand Up @@ -551,7 +548,6 @@ exports[`app generated files content - as-provided - myApp general application s

exports[`app generated files content - as-provided - myApp general application should configure vitest correctly 3`] = `
"{
"compilerOptions": {},
"files": [],
"include": [".nuxt/nuxt.d.ts"],
"references": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ describe('app', () => {
`);
expect(readJson(tree, 'myapp/tsconfig.json')).toMatchInlineSnapshot(`
{
"compilerOptions": {},
"extends": "../tsconfig.base.json",
"files": [],
"include": [
Expand Down
1 change: 0 additions & 1 deletion packages/nuxt/src/utils/create-ts-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export function createTsConfig(
) {
createAppTsConfig(host, options);
const json = {
compilerOptions: {},
files: [],
include: ['.nuxt/nuxt.d.ts'],
references: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function createLibraryFiles(host: Tree, options: NormalizedSchema) {
'.': {
import: './index.mjs',
require: './index.js',
types: './index.d.ts',
},
},
});
Expand Down
24 changes: 2 additions & 22 deletions packages/vue/src/utils/create-ts-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ export function createTsConfig(
relativePathToRootTsConfig: string
) {
if (isUsingTsSolutionSetup(host)) {
createTsConfigForTsSolution(
host,
projectRoot,
type,
options,
relativePathToRootTsConfig
);
createTsConfigForTsSolution(host, projectRoot, type, options);
} else {
createTsConfigForNonTsSolution(
host,
Expand All @@ -43,8 +37,7 @@ export function createTsConfigForTsSolution(
style?: string;
rootProject?: boolean;
unitTestRunner?: string;
},
relativePathToRootTsConfig: string
}
) {
const json = {
files: [],
Expand All @@ -56,18 +49,6 @@ export function createTsConfigForTsSolution(
],
} as any;

// inline tsconfig.base.json into the project
if (options.rootProject) {
json.compileOnSave = false;
json.compilerOptions = {
...shared.tsConfigBaseOptions,
...json.compilerOptions,
};
json.exclude = ['node_modules', 'tmp'];
} else {
json.extends = relativePathToRootTsConfig;
}

writeJson(host, `${projectRoot}/tsconfig.json`, json);

const tsconfigProjectPath = `${projectRoot}/tsconfig.${type}.json`;
Expand All @@ -82,7 +63,6 @@ export function createTsConfigForTsSolution(

return json;
});
} else {
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/workspace/src/generators/preset/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ async function createPreset(tree: Tree, options: Schema) {
addPlugin,
nxCloudToken: options.nxCloudToken,
useTsSolution: options.workspaces,
formatter: options.formatter,
});
} else if (options.preset === Preset.VueStandalone) {
const { applicationGenerator: vueApplicationGenerator } = require('@nx' +
Expand Down Expand Up @@ -165,6 +166,7 @@ async function createPreset(tree: Tree, options: Schema) {
addPlugin,
nxCloudToken: options.nxCloudToken,
useTsSolution: options.workspaces,
formatter: options.formatter,
});
} else if (options.preset === Preset.NuxtStandalone) {
const { applicationGenerator: nuxtApplicationGenerator } = require('@nx' +
Expand Down

0 comments on commit b9b388b

Please sign in to comment.