Skip to content

Commit

Permalink
Update entrance-decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
vilicvane committed Oct 15, 2023
2 parents 1296824 + 27b1fb3 commit 4d832b1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 31 additions & 11 deletions typescript/src/composables/package.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> {
return {
'entrance-decorator': esm ? '0.3' : '0.2',
};
}

const WORKSPACE_REFERENCE_DICT = {
pnpm: 'workspace:*',
Expand All @@ -36,10 +40,18 @@ const WORKSPACE_REFERENCE_DICT = {

export default composable<ResolvedOptions>(
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,
Expand All @@ -48,12 +60,16 @@ export default composable<ResolvedOptions>(
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,
]);

Expand Down Expand Up @@ -159,9 +175,9 @@ export default composable<ResolvedOptions>(
? 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];

Expand Down Expand Up @@ -193,7 +209,11 @@ export default composable<ResolvedOptions>(
dependencies: {
...data.dependencies,
...projectDependencies,
...(entrances ? projectEntrancesDependencies : undefined),
...(entrances
? packageOptions.type === 'module'
? esmProjectEntrancesDependencies
: cjsProjectEntrancesDependencies
: undefined),
..._.fromPairs(
referencedPackageNames.map(name => [name, workspaceReference]),
),
Expand Down
1 change: 0 additions & 1 deletion typescript/src/composables/tsconfig.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
14 changes: 10 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,18 @@
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"
"@typescript-eslint/parser" "^6.7.5"
"@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"

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4d832b1

Please sign in to comment.