Skip to content

Commit

Permalink
fix: make ${PROJECT_DIR} relative
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscon committed Aug 31, 2023
1 parent ab3f565 commit da9a52f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ $ pnpm nx semantic-release app-c --repositoryUrl "https://github.com/ruscon/nx-s

### Available Tokens

| Token | Expands into |
| ---------------- | --------------------------------------------------------------------------------------------- |
| ${PROJECT_DIR} | Resolves to the current project direcory (ex. `/Users/theunderscorer/nx-monorepo/apps/app-a`) |
| ${PROJECT_NAME} | Resolves to the current project name (ex. `app-a`) |
| ${WORKSPACE_DIR} | Resolves to the current workspace direcory (ex. `/Users/theunderscorer/nx-monorepo`) |
| Token | Expands into |
| ---------------- |--------------------------------------------------------------------------------------|
| ${PROJECT_DIR} | Resolves to the project's current *relative* directory (ex. `apps/app-a`) |
| ${PROJECT_NAME} | Resolves to the current project name (ex. `app-a`) |
| ${WORKSPACE_DIR} | Resolves to the current workspace direcory (ex. `/Users/theunderscorer/nx-monorepo`) |

The following options support tokens: `buildTarget`, `changelogFile`, `commitMessage`, `gitAssets`, `packageJsonDir`, `outputPath`, `plugins`'s options<sup>\*</sup>, and `tagFormat`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ describe('applyTokensToSemanticReleaseOptions', () => {
commitMessage: 'release ${PROJECT_NAME} in ${PROJECT_DIR}',
packageJsonDir: '${PROJECT_DIR}/src',
tagFormat: '${PROJECT_NAME}-v${version}',
outputPath: '${WORKSPACE_DIR}/dist/apps/${PROJECT_NAME}',
outputPath: 'dist/apps/${PROJECT_NAME}',
plugins: [
'@fake/plugin-without-options1',
'@fake/plugin-without-options1',
[
'@semantic-release/exec',
{
Expand All @@ -42,7 +42,7 @@ describe('applyTokensToSemanticReleaseOptions', () => {
fakeNumberOption: 10
}
],
'@fake/plugin-without-options2',
'@fake/plugin-without-options2',
]
};
});
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('applyTokensToSemanticReleaseOptions', () => {
mockTokens
);

expect(results.outputPath).toEqual(`./dist/apps/app-a`);
expect(results.outputPath).toEqual(`dist/apps/app-a`);
});

it('should return options with multiple tokens replaced', () => {
Expand All @@ -83,7 +83,7 @@ describe('applyTokensToSemanticReleaseOptions', () => {
);

expect(results.commitMessage).toEqual(`release app-a in apps/app-a`);
expect(results.outputPath).toEqual(`./dist/apps/app-a`);
expect(results.outputPath).toEqual(`dist/apps/app-a`);
});


Expand All @@ -94,7 +94,7 @@ describe('applyTokensToSemanticReleaseOptions', () => {
);

expect(results.plugins).toEqual([
'@fake/plugin-without-options1',
'@fake/plugin-without-options1',
[
'@semantic-release/exec',
{
Expand All @@ -105,7 +105,7 @@ describe('applyTokensToSemanticReleaseOptions', () => {
fakeNumberOption: 10
}
],
'@fake/plugin-without-options2',
'@fake/plugin-without-options2',
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { unwrapExecutorOptions } from '../../utils/executor';
import { applyTokensToSemanticReleaseOptions } from '../../config/apply-tokens';
import { getDefaultProjectRoot, GetProjectContext } from '../../common/project';
import { createProjectGraphAsync } from '@nx/devkit';
import path from "path";

export type SemanticReleaseOptions = Omit<
BaseSemanticReleaseOptions,
Expand Down Expand Up @@ -139,7 +140,7 @@ export function resolveOptions(

return applyTokensToSemanticReleaseOptions(mergedOptions, {
projectName: context.projectName as string,
projectDir: getDefaultProjectRoot(context),
projectDir: path.relative(context.cwd, getDefaultProjectRoot(context)),
workspaceDir: workspaceRoot,
});
}
Expand Down

0 comments on commit da9a52f

Please sign in to comment.