@sapphire-sh/utils 2.4.0 → 2.6.0

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.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@sapphire-sh/utils",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "description": "@sapphire-sh/utils",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./lib/index.js",
8
8
  "types": "./lib/index.d.ts",
9
9
  "bin": {
10
- "sapphire-bootstrap": "./bin/sapphire-bootstrap.js"
10
+ "sapphire-bootstrap": "bin/sapphire-bootstrap.js"
11
11
  },
12
12
  "exports": {
13
13
  ".": {
@@ -57,6 +57,7 @@
57
57
  },
58
58
  "files": [
59
59
  "bin/**/*",
60
+ "!bin/**/*.test.ts",
60
61
  "lib/**/*",
61
62
  "templates",
62
63
  "tsconfig.json",
@@ -2,7 +2,6 @@
2
2
  *.tsbuildinfo
3
3
  .DS_Store
4
4
  .env
5
- .github/context-mode/
6
5
  /build/
7
6
  /coverage/
8
7
  /data/
@@ -1,87 +0,0 @@
1
- import { execFileSync } from 'node:child_process';
2
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { dirname, join } from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
- import { afterEach, describe, expect, it } from 'vitest';
7
-
8
- const scriptPath = fileURLToPath(new URL('sapphire-bootstrap.js', import.meta.url));
9
- const workflowPath = join('.github', 'workflows', 'utils-update.yml');
10
- const prettierignoreTemplate = readFileSync(
11
- fileURLToPath(new URL('../templates/prettierignore.template', import.meta.url)),
12
- 'utf-8',
13
- );
14
- const prettierignoreSection = `# @sapphire-sh/utils:start\n${prettierignoreTemplate}# @sapphire-sh/utils:end`;
15
-
16
- const projects: string[] = [];
17
-
18
- const createProject = () => {
19
- const project = mkdtempSync(join(tmpdir(), 'sapphire-bootstrap-'));
20
- projects.push(project);
21
- return project;
22
- };
23
-
24
- const runBootstrap = (cwd: string) => execFileSync(process.execPath, [scriptPath], { cwd, encoding: 'utf-8' });
25
-
26
- afterEach(() => {
27
- for (const project of projects.splice(0)) {
28
- rmSync(project, { recursive: true, force: true });
29
- }
30
- });
31
-
32
- describe('sapphire-bootstrap', () => {
33
- it('copies the utils update workflow when the target does not have one', () => {
34
- const project = createProject();
35
-
36
- const output = runBootstrap(project);
37
-
38
- expect(output).toContain(`wrote ${workflowPath}`);
39
- expect(readFileSync(join(project, workflowPath), 'utf-8')).toContain('utils-update-template.yml');
40
- });
41
-
42
- it('keeps an existing utils update workflow and reports it as skipped', () => {
43
- const project = createProject();
44
- const existing = 'name: utils-update\n\njobs:\n update:\n with:\n rebuild_packages: example-package\n';
45
- mkdirSync(join(project, dirname(workflowPath)), { recursive: true });
46
- writeFileSync(join(project, workflowPath), existing);
47
-
48
- const output = runBootstrap(project);
49
-
50
- expect(output).toContain(`skipped ${workflowPath}`);
51
- expect(output).not.toContain(`wrote ${workflowPath}`);
52
- expect(readFileSync(join(project, workflowPath), 'utf-8')).toBe(existing);
53
- });
54
-
55
- it('skips the utils update workflow when the target is utils itself', () => {
56
- const project = createProject();
57
- writeFileSync(join(project, 'package.json'), JSON.stringify({ name: '@sapphire-sh/utils' }));
58
-
59
- const output = runBootstrap(project);
60
-
61
- expect(output).toContain(`skipped ${workflowPath}`);
62
- expect(existsSync(join(project, workflowPath))).toBe(false);
63
- });
64
-
65
- it('replaces only the marked section of an existing .prettierignore', () => {
66
- const project = createProject();
67
- const existing = '# @sapphire-sh/utils:start\nstale\n# @sapphire-sh/utils:end\n\nmigrations/meta\n';
68
- writeFileSync(join(project, '.prettierignore'), existing);
69
-
70
- runBootstrap(project);
71
-
72
- expect(readFileSync(join(project, '.prettierignore'), 'utf-8')).toBe(
73
- `${prettierignoreSection}\n\nmigrations/meta\n`,
74
- );
75
- });
76
-
77
- it('prepends the marked section to an existing .prettierignore without markers', () => {
78
- const project = createProject();
79
- writeFileSync(join(project, '.prettierignore'), 'migrations/meta\n');
80
-
81
- runBootstrap(project);
82
-
83
- expect(readFileSync(join(project, '.prettierignore'), 'utf-8')).toBe(
84
- `${prettierignoreSection}\n\nmigrations/meta\n`,
85
- );
86
- });
87
- });