diff --git a/package.json b/package.json index a2fd88f..da20e81 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "typescript": "^5.2.2" }, "devDependencies": { - "@mufan/eslint-plugin": "^0.2.0", + "@mufan/eslint-plugin": "^0.2.1", "@types/lodash": "^4.14.159", "@types/node": "^14.0.27", "eslint": "^8.51.0", diff --git a/typescript/src/composables/package.json.ts b/typescript/src/composables/package.json.ts index c8ba2aa..91cd3e8 100644 --- a/typescript/src/composables/package.json.ts +++ b/typescript/src/composables/package.json.ts @@ -25,9 +25,13 @@ const PROJECT_DEPENDENCY_DICT = { tslib: '2', }; -const PROJECT_ENTRANCES_DEPENDENCY_DICT = { - 'entrance-decorator': '0.2', -}; +function PROJECT_ENTRANCES_DEPENDENCY_DICT( + esm: boolean, +): Record { + return { + 'entrance-decorator': esm ? '0.3' : '0.2', + }; +} const WORKSPACE_REFERENCE_DICT = { pnpm: 'workspace:*', @@ -36,10 +40,18 @@ const WORKSPACE_REFERENCE_DICT = { export default composable( async ({packageManager, resolvedProjects: projects}) => { - const anyProjectWithEntrances = projects.some( + const projectWithEntrances = projects.filter( project => project.entrances.length > 0, ); + const anyESMProjectWithEntrances = projectWithEntrances.some( + project => project.package.type === 'module', + ); + + const anyCJSProjectWithEntrances = projectWithEntrances.some( + project => project.package.type !== 'module', + ); + const packagesWithTypeScriptProject = _.uniqBy( projects.map(project => project.package), packageOptions => packageOptions.packageJSONPath, @@ -48,12 +60,16 @@ export default composable( const [ rootDevDependencies, projectDependencies, - projectEntrancesDependencies, + esmProjectEntrancesDependencies, + cjsProjectEntrancesDependencies, ] = await Promise.all([ fetchPackageVersions(ROOT_DEV_DEPENDENCY_DICT), fetchPackageVersions(PROJECT_DEPENDENCY_DICT), - anyProjectWithEntrances - ? fetchPackageVersions(PROJECT_ENTRANCES_DEPENDENCY_DICT) + anyESMProjectWithEntrances + ? fetchPackageVersions(PROJECT_ENTRANCES_DEPENDENCY_DICT(true)) + : undefined, + anyCJSProjectWithEntrances + ? fetchPackageVersions(PROJECT_ENTRANCES_DEPENDENCY_DICT(false)) : undefined, ]); @@ -159,9 +175,9 @@ export default composable( ? singleProjectAndExports : undefined; - const entrances = - anyProjectWithEntrances && - packageProjects.some(project => project.entrances.length > 0); + const entrances = packageProjects.some( + project => project.entrances.length > 0, + ); const workspaceReference = WORKSPACE_REFERENCE_DICT[packageManager]; @@ -193,7 +209,11 @@ export default composable( dependencies: { ...data.dependencies, ...projectDependencies, - ...(entrances ? projectEntrancesDependencies : undefined), + ...(entrances + ? packageOptions.type === 'module' + ? esmProjectEntrancesDependencies + : cjsProjectEntrancesDependencies + : undefined), ..._.fromPairs( referencedPackageNames.map(name => [name, workspaceReference]), ), diff --git a/typescript/src/composables/tsconfig.json.ts b/typescript/src/composables/tsconfig.json.ts index dfd2df0..3cb3226 100644 --- a/typescript/src/composables/tsconfig.json.ts +++ b/typescript/src/composables/tsconfig.json.ts @@ -2,7 +2,6 @@ import * as Path from 'path'; import type {JSONFileOptions} from '@magicspace/core'; import {composable, json} from '@magicspace/core'; -import _ from 'lodash'; import type {ResolvedOptions} from '../library/index.js'; diff --git a/yarn.lock b/yarn.lock index 2152b88..52891e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -114,10 +114,10 @@ tslang "^0.1.27" tslib "^2.5.0" -"@mufan/eslint-plugin@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@mufan/eslint-plugin/-/eslint-plugin-0.2.0.tgz#68cbeef5151f74d6a167a2c55b688f6084553845" - integrity sha512-+xtp8Iz+yz+3xthULbvQFd1cTNlUoRMb5znE5AftyM8KY7hpfcKLykEkOfD3SvtW+eGQRY3yHTXlRo9V1DH4eQ== +"@mufan/eslint-plugin@^0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@mufan/eslint-plugin/-/eslint-plugin-0.2.1.tgz#1428e7b35108603919efd5467a577857d85cdc4a" + integrity sha512-Ku0QdISC0vrMfnWyT2B4QMj1fPygPq3Qg8i3Z6lnCGgBMBCNu4gAeL44swLlMwFwkjG4sVHsBnS975Kozix+ng== dependencies: "@types/eslint" "^8.44.4" "@typescript-eslint/eslint-plugin" "^6.7.5" @@ -125,6 +125,7 @@ "@typescript-eslint/utils" "^6.7.5" eslint-import-resolver-typescript "^3.6.1" eslint-plugin-import "^2.28.1" + eslint-plugin-only-warn "^1.1.0" tslib "^2.6.2" x-value "^0.1.16" @@ -845,6 +846,11 @@ eslint-plugin-import@^2.28.1: semver "^6.3.1" tsconfig-paths "^3.14.2" +eslint-plugin-only-warn@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-only-warn/-/eslint-plugin-only-warn-1.1.0.tgz#c6ddc37ddc4e72c121f07be565fcb7b6671fe78a" + integrity sha512-2tktqUAT+Q3hCAU0iSf4xAN1k9zOpjK5WO8104mB0rT/dGhOa09582HN5HlbxNbPRZ0THV7nLGvzugcNOSjzfA== + eslint-scope@^7.2.2: version "7.2.2" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.2.2.tgz#deb4f92563390f32006894af62a22dba1c46423f"