@meza/adr-tools 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.gitattributes +40 -0
  2. package/.github/renovate.json +5 -0
  3. package/.github/workflows/ci-pr.yml +50 -0
  4. package/.github/workflows/ci.yml +28 -20
  5. package/.github/workflows/sync-deps-to-main.yml +25 -0
  6. package/.github/workflows/sync-to-deps.yml +26 -0
  7. package/.releaserc.json +1 -13
  8. package/CHANGELOG.md +76 -0
  9. package/LICENSE +674 -0
  10. package/README.md +64 -5
  11. package/biome.json +148 -0
  12. package/dist/index.js +52 -82
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/adr.js +100 -126
  15. package/dist/lib/adr.js.map +1 -1
  16. package/dist/lib/config.js +20 -37
  17. package/dist/lib/config.js.map +1 -1
  18. package/dist/lib/links.js +8 -25
  19. package/dist/lib/links.js.map +1 -1
  20. package/dist/lib/links.test.js +35 -64
  21. package/dist/lib/links.test.js.map +1 -1
  22. package/dist/lib/manipulator.js +22 -23
  23. package/dist/lib/manipulator.js.map +1 -1
  24. package/dist/lib/manipulator.test.js +59 -63
  25. package/dist/lib/manipulator.test.js.map +1 -1
  26. package/dist/lib/numbering.js +9 -48
  27. package/dist/lib/numbering.js.map +1 -1
  28. package/dist/lib/numbering.test.js +27 -44
  29. package/dist/lib/numbering.test.js.map +1 -1
  30. package/dist/lib/prompt.js +14 -0
  31. package/dist/lib/prompt.js.map +1 -0
  32. package/dist/lib/prompt.test.js +33 -0
  33. package/dist/lib/prompt.test.js.map +1 -0
  34. package/dist/lib/template.js +13 -26
  35. package/dist/lib/template.js.map +1 -1
  36. package/dist/types/lib/adr.d.ts.map +1 -1
  37. package/dist/types/lib/config.d.ts.map +1 -1
  38. package/dist/types/lib/links.d.ts.map +1 -1
  39. package/dist/types/lib/manipulator.d.ts.map +1 -1
  40. package/dist/types/lib/numbering.d.ts.map +1 -1
  41. package/dist/types/lib/prompt.d.ts +2 -0
  42. package/dist/types/lib/prompt.d.ts.map +1 -0
  43. package/dist/types/lib/prompt.test.d.ts +2 -0
  44. package/dist/types/lib/prompt.test.d.ts.map +1 -0
  45. package/dist/types/lib/template.d.ts.map +1 -1
  46. package/dist/types/version.d.ts +1 -1
  47. package/dist/version.js +1 -4
  48. package/dist/version.js.map +1 -1
  49. package/doc/adr/.adr-sequence.lock +1 -0
  50. package/doc/adr/decisions.md +3 -0
  51. package/package.json +73 -47
  52. package/src/index.ts +52 -27
  53. package/src/lib/adr.ts +68 -73
  54. package/src/lib/config.ts +3 -3
  55. package/src/lib/links.test.ts +8 -24
  56. package/src/lib/links.ts +2 -2
  57. package/src/lib/manipulator.test.ts +44 -47
  58. package/src/lib/manipulator.ts +22 -10
  59. package/src/lib/numbering.test.ts +5 -9
  60. package/src/lib/numbering.ts +4 -5
  61. package/src/lib/prompt.test.ts +42 -0
  62. package/src/lib/prompt.ts +14 -0
  63. package/src/lib/template.ts +7 -3
  64. package/src/version.ts +1 -1
  65. package/tests/.adr-dir +1 -0
  66. package/tests/__snapshots__/generate-graph.e2e.test.ts.snap +23 -23
  67. package/tests/__snapshots__/init-adr-repository.e2e.test.ts.snap +1 -1
  68. package/tests/__snapshots__/linking-records.e2e.test.ts.snap +1 -1
  69. package/tests/__snapshots__/new-adr.e2e.test.ts.snap +1 -1
  70. package/tests/__snapshots__/superseding-records.e2e.test.ts.snap +1 -1
  71. package/tests/__snapshots__/toc-prefixing.e2e.test.ts.snap +1 -1
  72. package/tests/__snapshots__/use-template-override.e2e.test.ts.snap +1 -1
  73. package/tests/edit-on-create.e2e.test.ts +17 -12
  74. package/tests/funny-characters.e2e.test.ts +28 -21
  75. package/tests/generate-graph.e2e.test.ts +21 -13
  76. package/tests/init-adr-repository.e2e.test.ts +12 -8
  77. package/tests/linking-records.e2e.test.ts +21 -14
  78. package/tests/list-adrs.e2e.test.ts +23 -18
  79. package/tests/new-adr.e2e.test.ts +15 -12
  80. package/tests/superseding-records.e2e.test.ts +16 -11
  81. package/tests/toc-prefixing.e2e.test.ts +15 -11
  82. package/tests/use-template-override.e2e.test.ts +18 -10
  83. package/tests/work-form-other-directories.e2e.test.ts +14 -12
  84. package/tsconfig.json +9 -8
  85. package/vitest.config.e2e.ts +13 -0
  86. package/vitest.config.ts +8 -1
  87. package/.eslintignore +0 -2
  88. package/.eslintrc.json +0 -23
  89. package/.github/dependabot.yml +0 -14
  90. package/.github/workflows/auto-merge.yml +0 -14
  91. package/doc/adr/0001-record-architecture-decisions.md +0 -21
  92. package/doc/adr/0002-using-heavy-e2e-tests.md +0 -20
  93. /package/src/{environment.d.ts → types/environment.d.ts} +0 -0
@@ -1,13 +1,14 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach, vi } from 'vitest';
3
1
  import * as childProcess from 'child_process';
2
+ import { realpathSync, rmdirSync } from 'node:fs';
3
+ import * as os from 'os';
4
4
  import * as path from 'path';
5
5
  import * as fs from 'fs/promises';
6
- import * as os from 'os';
6
+ /* eslint-disable no-sync */
7
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
8
 
8
9
  describe('Superseding Adrs', () => {
9
10
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
- const command = `npx ts-node ${adr}`;
11
+ const command = `npx tsx ${adr}`;
11
12
 
12
13
  let adrDirectory: string;
13
14
  let workDir: string;
@@ -15,18 +16,22 @@ describe('Superseding Adrs', () => {
15
16
  beforeEach(async () => {
16
17
  // @ts-ignore
17
18
  process.env.ADR_DATE = '1992-01-12';
18
- workDir = await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'));
19
+ workDir = path.resolve(realpathSync(await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'))));
19
20
  adrDirectory = path.join(workDir, 'doc/adr');
20
21
  });
21
22
 
22
23
  afterEach(() => {
23
24
  vi.clearAllMocks();
24
- childProcess.execSync(`rm -rf ${workDir}`);
25
+ rmdirSync(workDir, {
26
+ recursive: true,
27
+ maxRetries: 3,
28
+ retryDelay: 500
29
+ });
25
30
  });
26
31
 
27
32
  it('should be able to supersede previous adrs', async () => {
28
- childProcess.execSync(`${command} new First Record`, { cwd: workDir });
29
- childProcess.execSync(`${command} new -s 1 Second Record`, { cwd: workDir });
33
+ childProcess.execSync(`${command} new First Record`, { timeout: 10000, cwd: workDir });
34
+ childProcess.execSync(`${command} new -s 1 Second Record`, { timeout: 10000, cwd: workDir });
30
35
 
31
36
  const first: string = path.join(adrDirectory, '0001-first-record.md');
32
37
  const second: string = path.join(adrDirectory, '0002-second-record.md');
@@ -39,9 +44,9 @@ describe('Superseding Adrs', () => {
39
44
  });
40
45
 
41
46
  it('should be able to supersede multiple records', async () => {
42
- childProcess.execSync(`${command} new First Record`, { cwd: workDir });
43
- childProcess.execSync(`${command} new Second Record`, { cwd: workDir });
44
- childProcess.execSync(`${command} new -s 1 -s 2 Third Record`, { cwd: workDir });
47
+ childProcess.execSync(`${command} new First Record`, { timeout: 10000, cwd: workDir });
48
+ childProcess.execSync(`${command} new Second Record`, { timeout: 10000, cwd: workDir });
49
+ childProcess.execSync(`${command} new -s 1 -s 2 Third Record`, { timeout: 10000, cwd: workDir });
45
50
 
46
51
  const first: string = path.join(adrDirectory, '0001-first-record.md');
47
52
  const second: string = path.join(adrDirectory, '0002-second-record.md');
@@ -1,13 +1,14 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach, vi } from 'vitest';
3
1
  import * as childProcess from 'child_process';
2
+ import { realpathSync, rmdirSync } from 'node:fs';
3
+ import * as os from 'os';
4
4
  import * as path from 'path';
5
5
  import * as fs from 'fs/promises';
6
- import * as os from 'os';
6
+ /* eslint-disable no-sync */
7
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
8
 
8
9
  describe('Generating TOC', () => {
9
10
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
- const command = `npx ts-node ${adr}`;
11
+ const command = `npx tsx ${adr}`;
11
12
 
12
13
  let adrDirectory: string;
13
14
  let workDir: string;
@@ -15,24 +16,27 @@ describe('Generating TOC', () => {
15
16
  beforeEach(async () => {
16
17
  // @ts-ignore
17
18
  process.env.ADR_DATE = '1992-01-12';
18
- workDir = await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'));
19
+ workDir = path.resolve(realpathSync(await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'))));
19
20
  adrDirectory = path.join(workDir, 'doc/adr');
20
21
  });
21
22
 
22
23
  afterEach(() => {
23
24
  vi.clearAllMocks();
24
- childProcess.execSync(`rm -rf ${workDir}`);
25
+ rmdirSync(workDir, {
26
+ recursive: true,
27
+ maxRetries: 3,
28
+ retryDelay: 500
29
+ });
25
30
  });
26
31
 
27
32
  it('should add a path prefix to the toc when there is one supplied', async () => {
28
- childProcess.execSync(`${command} new First Record`, { cwd: workDir });
29
- childProcess.execSync(`${command} new Second Record`, { cwd: workDir });
30
- childProcess.execSync(`${command} new Third Record`, { cwd: workDir });
31
- childProcess.execSync(`${command} generate toc -p foo/doc/adr/`, { cwd: workDir });
33
+ childProcess.execSync(`${command} new First Record`, { timeout: 10000, cwd: workDir });
34
+ childProcess.execSync(`${command} new Second Record`, { timeout: 10000, cwd: workDir });
35
+ childProcess.execSync(`${command} new Third Record`, { timeout: 10000, cwd: workDir });
36
+ childProcess.execSync(`${command} generate toc -p foo/doc/adr/`, { timeout: 10000, cwd: workDir });
32
37
 
33
38
  const tocFilePath: string = path.join(adrDirectory, 'decisions.md');
34
39
  const tocContent = await fs.readFile(tocFilePath, 'utf8');
35
40
  expect(tocContent).toMatchSnapshot();
36
41
  });
37
-
38
42
  });
@@ -1,13 +1,14 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach } from 'vitest';
3
1
  import * as childProcess from 'child_process';
2
+ import { realpathSync, rmdirSync } from 'node:fs';
3
+ import * as os from 'os';
4
4
  import * as path from 'path';
5
5
  import * as fs from 'fs/promises';
6
- import * as os from 'os';
6
+ /* eslint-disable no-sync */
7
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
8
 
8
9
  describe('Overriding templates', () => {
9
10
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
- const command = `npx ts-node ${adr}`;
11
+ const command = `npx tsx ${adr}`;
11
12
 
12
13
  let adrDirectory: string;
13
14
  let workDir: string;
@@ -15,21 +16,28 @@ describe('Overriding templates', () => {
15
16
  beforeEach(async () => {
16
17
  // @ts-ignore
17
18
  process.env.ADR_DATE = '1992-01-12';
18
- workDir = await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'));
19
+ workDir = path.resolve(realpathSync(await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'))));
19
20
  adrDirectory = path.join(workDir, 'doc/adr');
20
- childProcess.execSync(`${command} init ${adrDirectory}`, { cwd: workDir });
21
+ childProcess.execSync(`${command} init ${adrDirectory}`, { timeout: 10000, cwd: workDir });
21
22
  });
22
23
 
23
24
  afterEach(() => {
24
- childProcess.execSync(`rm -rf ${workDir}`);
25
+ rmdirSync(workDir, {
26
+ recursive: true,
27
+ maxRetries: 3,
28
+ retryDelay: 500
29
+ });
25
30
  });
26
31
 
27
32
  it('should use an override template if one exists', async () => {
28
33
  await fs.mkdir(path.join(adrDirectory, 'templates'), { recursive: true });
29
- await fs.writeFile(path.join(adrDirectory, 'templates', 'template.md'), '# This is an override template\nTITLE\nDATE\nNUMBER\nSTATUS');
34
+ await fs.writeFile(
35
+ path.join(adrDirectory, 'templates', 'template.md'),
36
+ '# This is an override template\nTITLE\nDATE\nNUMBER\nSTATUS'
37
+ );
30
38
 
31
- childProcess.execSync(`${command} new Example ADR`, { cwd: workDir });
32
- childProcess.execSync(`${command} new Another Example ADR`, { cwd: workDir });
39
+ childProcess.execSync(`${command} new Example ADR`, { timeout: 10000, cwd: workDir });
40
+ childProcess.execSync(`${command} new Another Example ADR`, { timeout: 10000, cwd: workDir });
33
41
 
34
42
  const expectedFile: string = path.join(adrDirectory, '0002-example-adr.md');
35
43
  const expectedFile2: string = path.join(adrDirectory, '0003-another-example-adr.md');
@@ -1,44 +1,46 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach } from 'vitest';
3
1
  import * as childProcess from 'child_process';
4
- import * as path from 'path';
5
2
  import * as fs from 'fs';
6
3
  import * as os from 'os';
4
+ import * as path from 'path';
5
+ /* eslint-disable no-sync */
6
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
7
 
8
8
  describe('deep directories', () => {
9
-
10
9
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
11
- const command = `npx ts-node ${adr}`;
10
+ const command = `npx tsx ${adr}`;
12
11
 
13
12
  let adrDirectory: string;
14
13
  let workDir: string;
15
14
 
16
15
  beforeEach(() => {
17
- workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'adr-'));
16
+ workDir = path.resolve(fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'adr-'))));
18
17
  adrDirectory = path.join(workDir, 'doc/adr');
19
- childProcess.execSync(`${command} init ${adrDirectory}`, { cwd: workDir });
18
+ childProcess.execSync(`${command} init ${adrDirectory}`, { timeout: 10000, cwd: workDir });
20
19
  });
21
20
 
22
21
  afterEach(() => {
23
- childProcess.execSync(`rm -rf ${workDir}`);
22
+ fs.rmdirSync(workDir, {
23
+ recursive: true,
24
+ maxRetries: 3,
25
+ retryDelay: 500
26
+ });
24
27
  });
25
28
 
26
29
  it('can work', () => {
27
30
  const innerPath = path.join(fs.mkdtempSync(path.resolve(workDir) + '/'), 'inner');
28
31
  fs.mkdirSync(innerPath, { recursive: true });
29
- childProcess.execSync(`${command} new this should exist`, { cwd: innerPath });
32
+ childProcess.execSync(`${command} new this should exist`, { timeout: 10000, cwd: innerPath });
30
33
  const expectedFile: string = path.join(adrDirectory, '0002-this-should-exist.md');
31
34
  expect(fs.existsSync(expectedFile)).toBeTruthy();
32
35
  });
33
36
 
34
37
  it('can work when there has been no config initiated', () => {
35
- childProcess.execSync(`rm -rf ${adrDirectory} ${workDir}/.adr-dir`);
38
+ childProcess.execSync(`rimraf ${adrDirectory} ${workDir}/.adr-dir`);
36
39
 
37
40
  const innerPath = path.join(fs.mkdtempSync(path.resolve(workDir) + '/'), 'inner');
38
41
  fs.mkdirSync(innerPath, { recursive: true });
39
- childProcess.execSync(`${command} new this should exist`, { cwd: innerPath });
42
+ childProcess.execSync(`${command} new this should exist`, { timeout: 10000, cwd: innerPath });
40
43
  const expectedFile: string = path.join(innerPath, 'doc', 'adr', '0001-this-should-exist.md');
41
44
  expect(fs.existsSync(expectedFile)).toBeTruthy();
42
45
  });
43
46
  });
44
-
package/tsconfig.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "extends": "@meza/tsconfig-base",
3
3
  "compilerOptions": {
4
- "target": "es6",
5
- "module": "commonjs",
4
+ "target": "ES2020",
5
+ "module": "NodeNext",
6
+ "moduleResolution": "NodeNext",
7
+ "esModuleInterop": true,
6
8
  "emitDeclarationOnly": false,
7
9
  "skipDefaultLibCheck": true,
8
10
  "skipLibCheck": true,
9
11
  "outDir": "./dist",
10
12
  "declarationDir": "./dist/types",
11
13
  "isolatedModules": true,
12
- "sourceRoot": "src"
14
+ "sourceRoot": "src",
15
+ "typeRoots": ["./node_modules/@types", "./src/types"]
13
16
  },
14
17
  "include": ["src/**/*"],
15
18
  "exclude": ["node_modules", "tests/**/*"],
16
19
  "ts-node": {
17
- "compilerOptions": {
18
- "module": "commonjs",
19
- "noPropertyAccessFromIndexSignature": false
20
- }
21
- }
20
+ "files": true
21
+ },
22
+ "files": ["src/types/environment.d.ts"]
22
23
  }
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ dir: 'tests',
6
+ testTimeout: 10000,
7
+ watch: false,
8
+ coverage: {
9
+ reportsDirectory: './reports/coverage/e2e',
10
+ reporter: ['text', 'json', 'html']
11
+ }
12
+ }
13
+ });
package/vitest.config.ts CHANGED
@@ -2,10 +2,17 @@ import { defineConfig } from 'vitest/config';
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
+ dir: 'src',
5
6
  testTimeout: 10000,
6
7
  watch: false,
8
+ poolOptions: {
9
+ forks: {
10
+ singleFork: true,
11
+ isolate: true
12
+ }
13
+ },
7
14
  coverage: {
8
- reportsDirectory: './reports/coverage',
15
+ reportsDirectory: './reports/coverage/unit',
9
16
  reporter: ['text', 'json', 'html']
10
17
  }
11
18
  }
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules
2
- dist
package/.eslintrc.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "extends": [
3
- "tailored-tunes",
4
- "plugin:json/recommended",
5
- "plugin:security/recommended"
6
- ],
7
- "root": true,
8
- "parser": "@typescript-eslint/parser",
9
- "plugins": [
10
- "json",
11
- "@typescript-eslint"
12
- ],
13
- "rules": {
14
- "no-console": "off",
15
- "security/detect-object-injection": 0,
16
- "security/detect-non-literal-fs-filename": 0
17
- },
18
- "env": {
19
- "commonjs": false,
20
- "es6": true,
21
- "node": true
22
- }
23
- }
@@ -1,14 +0,0 @@
1
- # To get started with Dependabot version updates, you'll need to specify which
2
- # package ecosystems to update and where the package manifests are located.
3
- # Please see the documentation for all configuration options:
4
- # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
-
6
- version: 2
7
- updates:
8
- - package-ecosystem: "npm" # See documentation for possible values
9
- directory: "/" # Location of package manifests
10
- versioning-strategy: increase-if-necessary
11
- commit-message:
12
- prefix: "chore: "
13
- schedule:
14
- interval: "daily"
@@ -1,14 +0,0 @@
1
- name: auto-merge dependabot
2
-
3
- on:
4
- pull_request:
5
-
6
- jobs:
7
- auto-merge:
8
- runs-on: ubuntu-latest
9
- steps:
10
- - uses: actions/checkout@v2
11
- - uses: ahmadnassri/action-dependabot-auto-merge@v2
12
- with:
13
- target: minor # includes patch updates!
14
- github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -1,21 +0,0 @@
1
- # 1. Record architecture decisions
2
-
3
- Date: 2022-06-22
4
-
5
- ## Status
6
-
7
- Accepted
8
-
9
- ## Context
10
-
11
- We need to record the architectural decisions made on this project.
12
-
13
- ## Decision
14
-
15
- We will use Architecture Decision Records, as [described by Michael Nygard](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions).
16
-
17
- ## Consequences
18
-
19
- See Michael Nygard's article, linked above.
20
- For a lightweight ADR toolset, see Nat Pryce's [adr-tools](https://github.com/npryce/adr-tools).
21
- > For a node version of the same tooling, see Meza's [adr-tools](https://github.com/meza/adr-tools).
@@ -1,20 +0,0 @@
1
- # 2. Using Heavy E2E Tests
2
-
3
- Date: 2022-06-22
4
-
5
- ## Status
6
-
7
- Accepted
8
-
9
- ## Context
10
-
11
- The original tool has an [exhaustive test suite](https://github.com/npryce/adr-tools/tree/master/tests) that allows us to make sure that we're backwards compatible.
12
-
13
- ## Decision
14
-
15
- We'll be re-implementing those tests for ourselves too. This means that we will be using the original examples,
16
- expectations and the ethos of invoking the tool with the given examples.
17
-
18
- ## Consequences
19
-
20
- The E2E test suite will be very slow to run and it can only be executed sequentially.