@0zd0/nx-oxfmt 0.0.1 → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
- "name": "@0zd0/nx-oxfmt",
3
- "version": "0.0.1",
4
- "main": "./src/index.js",
5
- "types": "./src/index.d.ts",
6
- "dependencies": {
7
- "@nx/devkit": "22.4.4",
8
- "oxfmt": "^0.28.0",
9
- "tslib": "^2.3.0"
10
- },
11
- "keywords": [
12
- "nx",
13
- "oxfmt",
14
- "oxc"
15
- ],
16
- "repository": {
17
- "type": "git",
18
- "url": "https://github.com/0zd0/nx-oxfmt",
19
- "directory": "nx-oxfmt"
20
- },
21
- "author": "0zd0",
22
- "license": "MIT",
23
- "generators": "./generators.json",
24
- "executors": "./executors.json"
25
- }
2
+ "name": "@0zd0/nx-oxfmt",
3
+ "version": "0.1.0",
4
+ "main": "./src/index.js",
5
+ "types": "./src/index.d.ts",
6
+ "dependencies": {
7
+ "@nx/devkit": "22.4.4",
8
+ "oxfmt": "^0.28.0"
9
+ },
10
+ "keywords": [
11
+ "nx",
12
+ "oxfmt",
13
+ "oxc"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/0zd0/nx-oxfmt",
18
+ "directory": "nx-oxfmt"
19
+ },
20
+ "author": "0zd0",
21
+ "license": "MIT",
22
+ "generators": "./generators.json",
23
+ "executors": "./executors.json",
24
+ "type": "commonjs"
25
+ }
@@ -0,0 +1,6 @@
1
+ export declare const NX_PLUGIN_NAME = "@0zd0/nx-oxfmt";
2
+ export declare const FORMAT_EXECUTOR_NAME = "fmt";
3
+ export declare const DEFAULT_FORMAT_TARGET_NAME = "fmt";
4
+ export declare const OXFMT_CONFIG_GLOB = ".oxfmtrc.{json,jsonc}";
5
+ export declare const OXFMT_BIN_NAME = "oxfmt";
6
+ export declare const NX_PROJECT_CONFIG_GLOB = "**/{package,project}.json";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NX_PROJECT_CONFIG_GLOB = exports.OXFMT_BIN_NAME = exports.OXFMT_CONFIG_GLOB = exports.DEFAULT_FORMAT_TARGET_NAME = exports.FORMAT_EXECUTOR_NAME = exports.NX_PLUGIN_NAME = void 0;
4
+ exports.NX_PLUGIN_NAME = '@0zd0/nx-oxfmt';
5
+ exports.FORMAT_EXECUTOR_NAME = 'fmt';
6
+ exports.DEFAULT_FORMAT_TARGET_NAME = 'fmt';
7
+ exports.OXFMT_CONFIG_GLOB = '.oxfmtrc.{json,jsonc}';
8
+ exports.OXFMT_BIN_NAME = 'oxfmt';
9
+ exports.NX_PROJECT_CONFIG_GLOB = '**/{package,project}.json';
10
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../packages/nx-oxfmt/src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,gBAAgB,CAAA;AACjC,QAAA,oBAAoB,GAAG,KAAK,CAAA;AAC5B,QAAA,0BAA0B,GAAG,KAAK,CAAA;AAClC,QAAA,iBAAiB,GAAG,uBAAuB,CAAA;AAC3C,QAAA,cAAc,GAAG,OAAO,CAAA;AAExB,QAAA,sBAAsB,GAAG,2BAA2B,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { PromiseExecutor } from '@nx/devkit';
2
+ import { FmtExecutorSchema } from './schema';
3
+ export declare const getOxfmtPath: (workspaceRoot: string) => string;
4
+ declare const runExecutor: PromiseExecutor<FmtExecutorSchema>;
5
+ export default runExecutor;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOxfmtPath = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const child_process_1 = require("child_process");
7
+ const getOxfmtPath = (workspaceRoot) => {
8
+ try {
9
+ return require.resolve('oxfmt/bin/oxfmt', { paths: [workspaceRoot] });
10
+ }
11
+ catch (_a) {
12
+ throw new Error('oxfmt not found');
13
+ }
14
+ };
15
+ exports.getOxfmtPath = getOxfmtPath;
16
+ const runExecutor = (options, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
17
+ var _a;
18
+ const projectRoot = (_a = context.projectsConfigurations.projects[context.projectName]) === null || _a === void 0 ? void 0 : _a.root;
19
+ const args = [];
20
+ if (options.check)
21
+ args.push('--check');
22
+ if (options.write)
23
+ args.push('--write');
24
+ if (options.config)
25
+ args.push(`--config=${options.config}`);
26
+ if (options.listDifferent)
27
+ args.push('--list-different');
28
+ if (options.withNodeModules)
29
+ args.push('--with-node-modules');
30
+ if (options.noErrorOnUnmatchedPattern)
31
+ args.push('--no-error-on-unmatched-pattern');
32
+ if (options.threads)
33
+ args.push(`--threads=${options.threads}`);
34
+ if (options.ignorePath) {
35
+ const paths = Array.isArray(options.ignorePath) ? options.ignorePath : [options.ignorePath];
36
+ paths.forEach((path) => args.push(`--ignore-path=${path}`));
37
+ }
38
+ if (Array.isArray(options.__unparsed__)) {
39
+ args.push(...options.__unparsed__);
40
+ }
41
+ args.push(projectRoot);
42
+ const oxfmtBin = (0, exports.getOxfmtPath)(context.root);
43
+ devkit_1.logger.info(`Running oxfmt for ${context.projectName}`);
44
+ return new Promise((resolve) => {
45
+ const child = (0, child_process_1.spawn)(oxfmtBin, args, {
46
+ cwd: context.root,
47
+ stdio: 'inherit',
48
+ });
49
+ child.on('close', (code) => {
50
+ if (code === 0) {
51
+ resolve({ success: true });
52
+ }
53
+ else {
54
+ devkit_1.logger.error(`oxfmt exited with code ${code}`);
55
+ resolve({ success: false });
56
+ }
57
+ });
58
+ child.on('error', (e) => {
59
+ devkit_1.logger.error(`Error starting oxfmt: ${e.message}`);
60
+ resolve({ success: false });
61
+ });
62
+ });
63
+ });
64
+ exports.default = runExecutor;
65
+ //# sourceMappingURL=fmt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fmt.js","sourceRoot":"","sources":["../../../../../../packages/nx-oxfmt/src/executors/fmt/fmt.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function initGenerator(tree: Tree): Promise<void>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = initGenerator;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const constants_1 = require("../../constants");
7
+ function initGenerator(tree) {
8
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
+ var _a;
10
+ const nxJson = (0, devkit_1.readNxJson)(tree) || {};
11
+ const hasPlugin = (_a = nxJson.plugins) === null || _a === void 0 ? void 0 : _a.some((plugin) => {
12
+ return typeof plugin === 'string' ?
13
+ plugin === constants_1.NX_PLUGIN_NAME
14
+ : plugin.plugin === constants_1.NX_PLUGIN_NAME;
15
+ });
16
+ if (!hasPlugin) {
17
+ nxJson.plugins = [
18
+ ...(nxJson.plugins || []),
19
+ {
20
+ plugin: constants_1.NX_PLUGIN_NAME,
21
+ options: {
22
+ formatTargetName: constants_1.DEFAULT_FORMAT_TARGET_NAME,
23
+ },
24
+ },
25
+ ];
26
+ (0, devkit_1.updateNxJson)(tree, nxJson);
27
+ }
28
+ });
29
+ }
30
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../../../packages/nx-oxfmt/src/generators/init/init.ts"],"names":[],"mappings":";;AAGA,gCAoBC;;AAvBD,uCAA2D;AAC3D,+CAA4E;AAE5E,SAA8B,aAAa,CAAC,IAAU;;;QAClD,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,IAAI,CAAC,IAAI,EAAE,CAAA;QACrC,MAAM,SAAS,GAAG,MAAA,MAAM,CAAC,OAAO,0CAAE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAC9C,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC;gBAC3B,MAAM,KAAK,0BAAc;gBAC7B,CAAC,CAAG,MAAM,CAAC,MAAM,KAAK,0BAAc,CAAA;QAC5C,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,MAAM,CAAC,OAAO,GAAG;gBACb,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;gBACzB;oBACI,MAAM,EAAE,0BAAc;oBACtB,OAAO,EAAE;wBACL,gBAAgB,EAAE,sCAA0B;qBAC/C;iBACJ;aACJ,CAAA;YACD,IAAA,qBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAC9B,CAAC;IACL,CAAC;CAAA"}
package/src/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { CreateNodesV2 } from '@nx/devkit';
2
+ interface OxfmtPluginOptions {
3
+ formatTargetName?: string;
4
+ }
5
+ export declare const createNodesV2: CreateNodesV2<OxfmtPluginOptions>;
6
+ export {};
package/src/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodesV2 = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const path_1 = require("path");
7
+ const constants_1 = require("./constants");
8
+ exports.createNodesV2 = [
9
+ constants_1.NX_PROJECT_CONFIG_GLOB,
10
+ (configFiles, options, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
11
+ return yield (0, devkit_1.createNodesFromFiles)((configFile, options) => {
12
+ var _a;
13
+ const projectRoot = (0, path_1.dirname)(configFile);
14
+ const target = {
15
+ executor: `${constants_1.NX_PLUGIN_NAME}:${constants_1.FORMAT_EXECUTOR_NAME}`,
16
+ options: Object.assign(Object.assign({}, options), { cwd: projectRoot }),
17
+ cache: true,
18
+ inputs: [
19
+ `{workspaceRoot}/${constants_1.OXFMT_CONFIG_GLOB}`,
20
+ `{projectRoot}/${constants_1.OXFMT_CONFIG_GLOB}`,
21
+ (0, devkit_1.joinPathFragments)('{projectRoot}', '**', '*'),
22
+ {
23
+ externalDependencies: ['oxfmt'],
24
+ },
25
+ ],
26
+ };
27
+ return {
28
+ projects: {
29
+ [projectRoot]: {
30
+ targets: {
31
+ [(_a = options.formatTargetName) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_FORMAT_TARGET_NAME]: target,
32
+ },
33
+ },
34
+ },
35
+ };
36
+ }, configFiles, options, context);
37
+ }),
38
+ ];
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/nx-oxfmt/src/index.ts"],"names":[],"mappings":";;;;AAAA,uCAKmB;AACnB,+BAA8B;AAC9B,2CAMoB;AAMP,QAAA,aAAa,GAAsC;IAC5D,kCAAsB;IACtB,CAAO,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QACpC,OAAO,MAAM,IAAA,6BAAoB,EAC7B,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE;;YACpB,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,UAAU,CAAC,CAAA;YAEvC,MAAM,MAAM,GAAwB;gBAChC,QAAQ,EAAE,GAAG,0BAAc,IAAI,gCAAoB,EAAE;gBACrD,OAAO,kCACA,OAAO,KACV,GAAG,EAAE,WAAW,GACnB;gBACD,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE;oBACJ,mBAAmB,6BAAiB,EAAE;oBACtC,iBAAiB,6BAAiB,EAAE;oBACpC,IAAA,0BAAiB,EAAC,eAAe,EAAE,IAAI,EAAE,GAAG,CAAC;oBAC7C;wBACI,oBAAoB,EAAE,CAAC,OAAO,CAAC;qBAClC;iBACJ;aACJ,CAAA;YAED,OAAO;gBACH,QAAQ,EAAE;oBACN,CAAC,WAAW,CAAC,EAAE;wBACX,OAAO,EAAE;4BACL,CAAC,MAAA,OAAO,CAAC,gBAAgB,mCAAI,sCAA0B,CAAC,EAAE,MAAM;yBACnE;qBACJ;iBACJ;aACJ,CAAA;QACL,CAAC,EACD,WAAW,EACX,OAAO,EACP,OAAO,CACV,CAAA;IACL,CAAC,CAAA;CACJ,CAAA"}
package/eslint.config.mjs DELETED
@@ -1,34 +0,0 @@
1
- import baseConfig from '../eslint.config.mjs'
2
-
3
- export default [
4
- ...baseConfig,
5
- {
6
- files: ['**/*.json'],
7
- rules: {
8
- '@nx/dependency-checks': [
9
- 'error',
10
- {
11
- ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}'],
12
- },
13
- ],
14
- },
15
- languageOptions: {
16
- parser: await import('jsonc-eslint-parser'),
17
- },
18
- },
19
- {
20
- files: ['**/package.json', '**/generators.json'],
21
- rules: {
22
- '@nx/nx-plugin-checks': 'error',
23
- '@nx/dependency-checks': [
24
- 'error',
25
- {
26
- ignoredDependencies: ['oxfmt'],
27
- },
28
- ],
29
- },
30
- languageOptions: {
31
- parser: await import('jsonc-eslint-parser'),
32
- },
33
- },
34
- ]
package/jest.config.cts DELETED
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- displayName: 'nx-oxfmt',
3
- preset: '../jest.preset.js',
4
- testEnvironment: 'node',
5
- transform: {
6
- '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
7
- },
8
- moduleFileExtensions: ['ts', 'js', 'html'],
9
- coverageDirectory: '../coverage/nx-oxfmt',
10
- }
package/project.json DELETED
@@ -1,63 +0,0 @@
1
- {
2
- "name": "nx-oxfmt",
3
- "$schema": "../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "nx-oxfmt/src",
5
- "projectType": "library",
6
- "release": {
7
- "version": {
8
- "manifestRootsToUpdate": ["dist/{projectRoot}"],
9
- "currentVersionResolver": "git-tag",
10
- "fallbackCurrentVersionResolver": "disk"
11
- }
12
- },
13
- "tags": [],
14
- "targets": {
15
- "build": {
16
- "executor": "@nx/js:tsc",
17
- "outputs": ["{options.outputPath}"],
18
- "options": {
19
- "outputPath": "dist/nx-oxfmt",
20
- "main": "nx-oxfmt/src/index.ts",
21
- "tsConfig": "nx-oxfmt/tsconfig.lib.json",
22
- "assets": [
23
- "nx-oxfmt/*.md",
24
- {
25
- "input": "./nx-oxfmt/src",
26
- "glob": "**/!(*.ts)",
27
- "output": "./src"
28
- },
29
- {
30
- "input": "./nx-oxfmt/src",
31
- "glob": "**/*.d.ts",
32
- "output": "./src"
33
- },
34
- {
35
- "input": "./nx-oxfmt",
36
- "glob": "generators.json",
37
- "output": "."
38
- },
39
- {
40
- "input": "./nx-oxfmt",
41
- "glob": "executors.json",
42
- "output": "."
43
- }
44
- ]
45
- }
46
- },
47
- "nx-release-publish": {
48
- "options": {
49
- "packageRoot": "dist/{projectRoot}"
50
- }
51
- },
52
- "lint": {
53
- "executor": "@nx/eslint:lint"
54
- },
55
- "test": {
56
- "executor": "@nx/jest:jest",
57
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
58
- "options": {
59
- "jestConfig": "nx-oxfmt/jest.config.cts"
60
- }
61
- }
62
- }
63
- }
package/src/constants.ts DELETED
@@ -1,9 +0,0 @@
1
- export const NX_PLUGIN_NAME = '@0zd0/nx-oxfmt'
2
- export const FORMAT_EXECUTOR_NAME = 'fmt'
3
- export const DEFAULT_FORMAT_TARGET_NAME = 'fmt'
4
- export const OXFMT_CONFIG_GLOB = '.oxfmtrc.{json,jsonc}'
5
- export const OXFMT_BIN_NAME = 'oxfmt'
6
-
7
- export const EXEC = 'pnpm exec'
8
-
9
- export const NX_PROJECT_CONFIG_GLOB = '**/{package,project}.json'
@@ -1,150 +0,0 @@
1
- import { ExecutorContext, logger } from '@nx/devkit'
2
-
3
- import { FmtExecutorSchema } from './schema'
4
- import executor from './fmt'
5
- import { spawn, ChildProcess } from 'child_process'
6
- import { EXEC, OXFMT_BIN_NAME } from '../../constants'
7
-
8
- jest.mock('child_process')
9
- const mockedSpawn = jest.mocked(spawn)
10
- jest.mock('@nx/devkit', () => ({
11
- ...jest.requireActual('@nx/devkit'),
12
- logger: {
13
- info: jest.fn(),
14
- error: jest.fn(),
15
- },
16
- getPackageManagerCommand: jest.fn().mockReturnValue({ exec: 'pnpm exec' }),
17
- }))
18
-
19
- const context: ExecutorContext = {
20
- root: '/root',
21
- cwd: '/root',
22
- isVerbose: false,
23
- projectName: 'my-project',
24
- projectGraph: {
25
- nodes: {
26
- 'my-project': {
27
- type: 'app',
28
- name: 'my-project',
29
- data: {
30
- root: 'apps/my-project',
31
- },
32
- },
33
- },
34
- dependencies: {},
35
- },
36
- projectsConfigurations: {
37
- projects: {
38
- 'my-project': {
39
- root: 'apps/my-project',
40
- },
41
- },
42
- version: 2,
43
- },
44
- nxJsonConfiguration: {},
45
- }
46
-
47
- describe('Fmt Executor', () => {
48
- let mockChildProcess: { on: jest.Mock<unknown, [string, (...args: unknown[]) => void]> }
49
- let mockOn: jest.Mock<unknown, [string, (...args: unknown[]) => void]>
50
-
51
- beforeEach(() => {
52
- jest.clearAllMocks()
53
-
54
- mockOn = jest.fn().mockImplementation(function (this: unknown) {
55
- return this
56
- })
57
- mockChildProcess = {
58
- on: mockOn,
59
- }
60
-
61
- mockedSpawn.mockReturnValue(mockChildProcess as unknown as ChildProcess)
62
- })
63
-
64
- const runAndEmit = async (options: FmtExecutorSchema, exitCode = 0) => {
65
- const promise = executor(options, context)
66
-
67
- const closeCall = mockOn.mock.calls.find((call) => call[0] === 'close')
68
- if (closeCall) {
69
- closeCall[1](exitCode)
70
- }
71
-
72
- return promise
73
- }
74
-
75
- it('should run oxfmt with base paths', async () => {
76
- const result = await runAndEmit({ write: true })
77
-
78
- expect(result.success).toBe(true)
79
- expect(spawn).toHaveBeenCalledWith(
80
- `${EXEC} ${OXFMT_BIN_NAME}`,
81
- ['--write', 'apps/my-project'],
82
- expect.objectContaining({ cwd: '/root', shell: true }),
83
- )
84
- })
85
-
86
- it('should correctly pass all boolean flags', async () => {
87
- await runAndEmit({
88
- check: true,
89
- listDifferent: true,
90
- withNodeModules: true,
91
- noErrorOnUnmatchedPattern: true,
92
- })
93
-
94
- const args = mockedSpawn.mock.calls[0][1]
95
- expect(args).toContain('--check')
96
- expect(args).toContain('--list-different')
97
- expect(args).toContain('--with-node-modules')
98
- expect(args).toContain('--no-error-on-unmatched-pattern')
99
- })
100
-
101
- it('should handle threads and config values', async () => {
102
- await runAndEmit({ threads: 4, config: 'custom.json' })
103
-
104
- const args = mockedSpawn.mock.calls[0][1]
105
- expect(args).toContain('--threads=4')
106
- expect(args).toContain('--config=custom.json')
107
- })
108
-
109
- it('should handle ignorePath array', async () => {
110
- await runAndEmit({ ignorePath: ['dist', '.next'] })
111
-
112
- const args = mockedSpawn.mock.calls[0][1]
113
- expect(args).toContain('--ignore-path=dist')
114
- expect(args).toContain('--ignore-path=.next')
115
- })
116
-
117
- it('should pass unknown arguments via __unparsed__', async () => {
118
- await runAndEmit({
119
- write: true,
120
- __unparsed__: ['--max-width=120', '--no-semi'],
121
- })
122
-
123
- const args = mockedSpawn.mock.calls[0][1]
124
- expect(args).toContain('--max-width=120')
125
- expect(args).toContain('--no-semi')
126
- expect(args[args.length - 1]).toBe('apps/my-project')
127
- })
128
-
129
- it('should return success: false on non-zero exit code', async () => {
130
- const result = await runAndEmit({}, 1)
131
-
132
- expect(result.success).toBe(false)
133
- expect(logger.error).toHaveBeenCalledWith(
134
- expect.stringContaining('oxfmt exited with code 1'),
135
- )
136
- })
137
-
138
- it('should handle system spawn error (error event)', async () => {
139
- const promise = executor({}, context)
140
-
141
- const errorCall = mockOn.mock.calls.find((call) => call[0] === 'error')
142
- if (errorCall) {
143
- errorCall[1](new Error('Spawn failed'))
144
- }
145
-
146
- const result = await promise
147
- expect(result.success).toBe(false)
148
- expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('Error starting oxfmt'))
149
- })
150
- })
@@ -1,52 +0,0 @@
1
- import { PromiseExecutor, logger, getPackageManagerCommand } from '@nx/devkit'
2
- import { spawn } from 'child_process'
3
- import { FmtExecutorSchema } from './schema'
4
- import { OXFMT_BIN_NAME } from '../../constants'
5
-
6
- const runExecutor: PromiseExecutor<FmtExecutorSchema> = async (options, context) => {
7
- const projectRoot = context.projectsConfigurations.projects[context.projectName]?.root
8
- const args: string[] = []
9
-
10
- if (options.check) args.push('--check')
11
- if (options.write) args.push('--write')
12
- if (options.config) args.push(`--config=${options.config}`)
13
- if (options.listDifferent) args.push('--list-different')
14
- if (options.withNodeModules) args.push('--with-node-modules')
15
- if (options.noErrorOnUnmatchedPattern) args.push('--no-error-on-unmatched-pattern')
16
- if (options.threads) args.push(`--threads=${options.threads}`)
17
- if (options.ignorePath) {
18
- const paths = Array.isArray(options.ignorePath) ? options.ignorePath : [options.ignorePath]
19
- paths.forEach((path) => args.push(`--ignore-path=${path}`))
20
- }
21
- if (Array.isArray(options.__unparsed__)) {
22
- args.push(...options.__unparsed__)
23
- }
24
-
25
- args.push(projectRoot)
26
-
27
- logger.info(`Running oxfmt for ${context.projectName}`)
28
-
29
- return new Promise((resolve) => {
30
- const child = spawn(`${getPackageManagerCommand().exec} ${OXFMT_BIN_NAME}`, args, {
31
- cwd: context.root,
32
- stdio: 'inherit',
33
- shell: true,
34
- })
35
-
36
- child.on('close', (code) => {
37
- if (code === 0) {
38
- resolve({ success: true })
39
- } else {
40
- logger.error(`oxfmt exited with code ${code}`)
41
- resolve({ success: false })
42
- }
43
- })
44
-
45
- child.on('error', (e) => {
46
- logger.error(`Error starting oxfmt: ${e.message}`)
47
- resolve({ success: false })
48
- })
49
- })
50
- }
51
-
52
- export default runExecutor
@@ -1,69 +0,0 @@
1
- import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'
2
- import { Tree, readNxJson, updateNxJson } from '@nx/devkit'
3
-
4
- import initGenerator from './init'
5
- import { DEFAULT_FORMAT_TARGET_NAME, NX_PLUGIN_NAME } from '../../constants'
6
-
7
- describe('init generator', () => {
8
- let tree: Tree
9
-
10
- beforeEach(() => {
11
- tree = createTreeWithEmptyWorkspace()
12
- })
13
-
14
- it('should add the plugin to nx.json if not present', async () => {
15
- await initGenerator(tree)
16
-
17
- const nxJson = readNxJson(tree)
18
-
19
- expect(nxJson?.plugins).toContainEqual({
20
- plugin: NX_PLUGIN_NAME,
21
- options: {
22
- formatTargetName: DEFAULT_FORMAT_TARGET_NAME,
23
- },
24
- })
25
- })
26
-
27
- it('should not add the plugin if already present as object', async () => {
28
- const nxJson = readNxJson(tree) || {}
29
- nxJson.plugins = [
30
- ...(nxJson.plugins || []),
31
- {
32
- plugin: NX_PLUGIN_NAME,
33
- options: {
34
- formatTargetName: 'custom-lint-name',
35
- },
36
- },
37
- ]
38
- updateNxJson(tree, nxJson)
39
-
40
- await initGenerator(tree)
41
-
42
- const updatedNxJson = readNxJson(tree)
43
-
44
- const myPlugins = updatedNxJson?.plugins?.filter((plugin) => {
45
- return typeof plugin === 'string' ?
46
- plugin === NX_PLUGIN_NAME
47
- : plugin.plugin === NX_PLUGIN_NAME
48
- })
49
-
50
- expect(myPlugins).toHaveLength(1)
51
- })
52
-
53
- it('should not add the plugin if already present as string', async () => {
54
- const nxJson = readNxJson(tree) || {}
55
- nxJson.plugins = [...(nxJson.plugins || []), NX_PLUGIN_NAME]
56
- updateNxJson(tree, nxJson)
57
-
58
- await initGenerator(tree)
59
-
60
- const updatedNxJson = readNxJson(tree)
61
- const myPlugins = updatedNxJson?.plugins?.filter((plugin) => {
62
- return typeof plugin === 'string' ?
63
- plugin === NX_PLUGIN_NAME
64
- : plugin.plugin === NX_PLUGIN_NAME
65
- })
66
-
67
- expect(myPlugins).toHaveLength(1)
68
- })
69
- })
@@ -1,24 +0,0 @@
1
- import { readNxJson, Tree, updateNxJson } from '@nx/devkit'
2
- import { DEFAULT_FORMAT_TARGET_NAME, NX_PLUGIN_NAME } from '../../constants'
3
-
4
- export default async function initGenerator(tree: Tree) {
5
- const nxJson = readNxJson(tree) || {}
6
- const hasPlugin = nxJson.plugins?.some((plugin) => {
7
- return typeof plugin === 'string' ?
8
- plugin === NX_PLUGIN_NAME
9
- : plugin.plugin === NX_PLUGIN_NAME
10
- })
11
-
12
- if (!hasPlugin) {
13
- nxJson.plugins = [
14
- ...(nxJson.plugins || []),
15
- {
16
- plugin: NX_PLUGIN_NAME,
17
- options: {
18
- formatTargetName: DEFAULT_FORMAT_TARGET_NAME,
19
- },
20
- },
21
- ]
22
- updateNxJson(tree, nxJson)
23
- }
24
- }
package/src/index.ts DELETED
@@ -1,59 +0,0 @@
1
- import {
2
- createNodesFromFiles,
3
- CreateNodesV2,
4
- joinPathFragments,
5
- TargetConfiguration,
6
- } from '@nx/devkit'
7
- import { dirname } from 'path'
8
- import {
9
- DEFAULT_FORMAT_TARGET_NAME,
10
- FORMAT_EXECUTOR_NAME,
11
- NX_PLUGIN_NAME,
12
- NX_PROJECT_CONFIG_GLOB,
13
- OXFMT_CONFIG_GLOB,
14
- } from './constants'
15
-
16
- interface OxfmtPluginOptions {
17
- formatTargetName?: string
18
- }
19
-
20
- export const createNodesV2: CreateNodesV2<OxfmtPluginOptions> = [
21
- NX_PROJECT_CONFIG_GLOB,
22
- async (configFiles, options, context) => {
23
- return await createNodesFromFiles(
24
- (configFile, options) => {
25
- const projectRoot = dirname(configFile)
26
-
27
- const target: TargetConfiguration = {
28
- executor: `${NX_PLUGIN_NAME}:${FORMAT_EXECUTOR_NAME}`,
29
- options: {
30
- ...options,
31
- cwd: projectRoot,
32
- },
33
- cache: true,
34
- inputs: [
35
- `{workspaceRoot}/${OXFMT_CONFIG_GLOB}`,
36
- `{projectRoot}/${OXFMT_CONFIG_GLOB}`,
37
- joinPathFragments('{projectRoot}', '**', '*'),
38
- {
39
- externalDependencies: ['oxfmt'],
40
- },
41
- ],
42
- }
43
-
44
- return {
45
- projects: {
46
- [projectRoot]: {
47
- targets: {
48
- [options.formatTargetName ?? DEFAULT_FORMAT_TARGET_NAME]: target,
49
- },
50
- },
51
- },
52
- }
53
- },
54
- configFiles,
55
- options,
56
- context,
57
- )
58
- },
59
- ]
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "commonjs"
5
- },
6
- "files": [],
7
- "include": [],
8
- "references": [
9
- {
10
- "path": "./tsconfig.lib.json"
11
- },
12
- {
13
- "path": "./tsconfig.spec.json"
14
- }
15
- ]
16
- }
package/tsconfig.lib.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../dist/out-tsc",
5
- "declaration": true,
6
- "types": ["node"]
7
- },
8
- "include": ["src/**/*.ts"],
9
- "exclude": ["jest.config.ts", "jest.config.cts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10
- }
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../dist/out-tsc",
5
- "module": "commonjs",
6
- "moduleResolution": "node10",
7
- "types": ["jest", "node"]
8
- },
9
- "include": [
10
- "jest.config.ts",
11
- "jest.config.cts",
12
- "src/**/*.test.ts",
13
- "src/**/*.spec.ts",
14
- "src/**/*.d.ts"
15
- ]
16
- }