Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens committed Feb 9, 2023
1 parent 7beca1a commit 9fde27e
Show file tree
Hide file tree
Showing 24 changed files with 194 additions and 171 deletions.
12 changes: 6 additions & 6 deletions packages/deno/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
"$schema": "http://json-schema.org/schema",
"executors": {
"build": {
"implementation": "./src/executors/build/executor",
"implementation": "./src/executors/build/build.impl",
"schema": "./src/executors/build/schema.json",
"description": "build executor"
"description": "Output a single JavaScript file with all dependencies."
},
"serve": {
"implementation": "./src/executors/serve/executor",
"schema": "./src/executors/serve/schema.json",
"description": "serve executor"
"description": "Run a JavaScript or TypeScript program in watch mode"
},
"lint": {
"implementation": "./src/executors/lint/executor",
"implementation": "./src/executors/lint/lint.impl",
"schema": "./src/executors/lint/schema.json",
"description": "lint executor"
"description": "Lint JavaScript/TypeScript source code"
},
"test": {
"implementation": "./src/executors/test/executor",
"schema": "./src/executors/test/schema.json",
"description": "test executor"
"description": "Test JavaScript/TypeScript source code"
}
}
}
14 changes: 5 additions & 9 deletions packages/deno/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
"application": {
"factory": "./src/generators/application/generator",
"schema": "./src/generators/application/schema.json",
"description": "application generator",
"aliases": [
"app"
]
"description": "Create a new Deno application",
"aliases": ["app"]
},
"library": {
"factory": "./src/generators/library/library",
"schema": "./src/generators/library/schema.json",
"description": "library generator",
"aliases": [
"lib"
]
"description": "Create a new Deno library",
"aliases": ["lib"]
},
"init": {
"factory": "./src/generators/init/generator",
"schema": "./src/generators/init/schema.json",
"description": "init generator"
"description": "Initlize configurations for Deno"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { ExecutorContext, workspaceRoot } from '@nrwl/devkit';
import { workspaceRoot } from '@nrwl/devkit';
import { dirname, join, resolve } from 'path';
import { BuildExecutorSchema } from './schema';

import { ensureDirSync } from 'fs-extra';
import { processTypeCheckOption } from '../../utils/arg-utils';
import { runDeno } from '../../utils/run-deno';

export default async function runExecutor(
options: BuildExecutorSchema,
context: ExecutorContext
) {
export async function denoBuildExecutor(options: BuildExecutorSchema) {
const opts = normalizeOptions(options);
const args = createArgs(opts);

Expand Down Expand Up @@ -49,22 +47,7 @@ function createArgs(options: BuildExecutorSchema) {
args.push(`--cert=${options.cert}`);
}
if (options.check !== undefined) {
// TODO(caleb): why are boolean args being parsed as strings?
if (
options.check === 'none' ||
options.check === false ||
options.check === 'false'
) {
args.push('--no-check');
} else if (
options.check === 'local' ||
options.check === true ||
options.check === 'true'
) {
args.push('--check');
} else if (options.check === 'all') {
args.push('--check=all');
}
args.push(processTypeCheckOption(options.check));
}

if (options.lockWrite) {
Expand Down Expand Up @@ -113,3 +96,4 @@ function createArgs(options: BuildExecutorSchema) {

return args;
}
export default denoBuildExecutor;
2 changes: 1 addition & 1 deletion packages/deno/src/executors/build/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DenoTypeCheck } from '../../utils/schema-types';
import { DenoTypeCheck } from '../../utils/arg-utils';

export interface BuildExecutorSchema {
denoConfig: string;
Expand Down
15 changes: 6 additions & 9 deletions packages/deno/src/executors/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "http://json-schema.org/schema",
"version": 2,
"cli": "nx",
"title": "Build executor",
"description": "",
"title": "Deno Build Executor",
"description": "Output a single JavaScript file with all dependencies",
"type": "object",
"properties": {
"denoConfig": {
Expand All @@ -23,13 +23,11 @@
"description": "Load certificate authority from PEM encoded file."
},
"check": {
"anyOf": [{ "type": "boolean" }, { "type": "string" }]
},
"check": {
"anyOf": [{ "type": "boolean" }, { "type": "string" }],
"description": "Type-check modules. Deno does not type-check modules automatically from v1.23 onwards. Set this option to enable type-checking or use the 'deno check' subcommand. If the value of '--check=all' is supplied, diagonstic errors from remote modules will be included.",
"oneOf": [{ "type": "boolean" }, { "type": "string" }],
"enum": ["none", "local", "all"],
"default": "local"
"default": "local",
"x-priority": "important"
},
"lockWrite": {
"type": "boolean",
Expand Down Expand Up @@ -58,13 +56,12 @@
},
"reload": {
"description": "Reload source code cache (recompile TypeScript)",
"anyOf": [{ "type": "boolean" }, { "type": "string" }]
"oneOf": [{ "type": "boolean" }, { "type": "string" }]
},
"unstable": {
"type": "boolean",
"description": "Enable unstable features and APIs."
},

"watch": {
"type": "boolean",
"description": "Watch for file changes and restart process automatically. Only local files form entry point module graph are watched."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ExecutorContext } from '@nrwl/devkit';
import { ExecutorContext, ProjectConfiguration } from '@nrwl/devkit';
import { runDeno } from '../../utils/run-deno';
import { LintExecutorSchema } from './schema';

interface LintExecutorNormalizedSchema extends LintExecutorSchema {
lintDir: string;
}
export async function denoLintExecutor(
options: LintExecutorSchema,
context: ExecutorContext
) {
const args = normalizeOptions(options);
const projectConfig =
context.projectGraph?.nodes?.[context.projectName]?.data;

Expand All @@ -15,9 +17,9 @@ export async function denoLintExecutor(
`Could not find project configuration for ${context.projectName} in executor context.`
);
}
const opts = normalizeOpitons(options, projectConfig);

args.push(`--config=${options.denoConfig}`);
args.push(projectConfig.sourceRoot || projectConfig.root);
const args = createArgs(opts);

const runningDenoProcess = runDeno(args);

Expand All @@ -28,7 +30,17 @@ export async function denoLintExecutor(
});
}

function normalizeOptions(options: LintExecutorSchema) {
function normalizeOpitons(
options: LintExecutorSchema,
projectConfig: ProjectConfiguration
): LintExecutorNormalizedSchema {
return {
...options,
lintDir: projectConfig.sourceRoot || projectConfig.root,
};
}

function createArgs(options: LintExecutorNormalizedSchema) {
const args: Array<string | boolean> = ['lint'];

if (options.compact) {
Expand Down Expand Up @@ -67,6 +79,9 @@ function normalizeOptions(options: LintExecutorSchema) {
args.push('--watch');
}

args.push(`--config=${options.denoConfig}`);
args.push(options.lintDir);

return args;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/deno/src/executors/lint/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "http://json-schema.org/schema",
"version": 2,
"cli": "nx",
"title": "Lint executor",
"description": "",
"title": "Deno Lint executor",
"description": "Test JavaScript/TypeScript source code with Deno",
"type": "object",
"properties": {
"denoConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/deno/src/executors/serve/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DenoTypeCheck } from '../../utils/schema-types';
import { DenoTypeCheck } from '../../utils/arg-utils';

export interface ServeExecutorSchema {
buildTarget: string;
Expand Down
23 changes: 13 additions & 10 deletions packages/deno/src/executors/serve/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@
"$schema": "http://json-schema.org/schema",
"version": 2,
"cli": "nx",
"title": "Serve executor",
"description": "",
"title": "Deno Serve Executor",
"description": "Run a JavaScript or TypeScript program in watch mode",
"type": "object",
"properties": {
"buildTarget": {
"type": "string",
"description": "The target use to build your Deno application. The build target options are used to pass to 'deno run'."
"description": "The target use to build your Deno application. The build target options are used to pass to 'deno run' and does not build your application. This option is optional if the 'denoConfig' and 'main' options are provided.",
"x-priority": "important"
},
"denoConfig": {
"type": "string",
"description": "Provide a different Deno config file than what is specified in the buildTarget"
"description": "Provide a different Deno config file than what is specified in the 'buildTarget'. This option is required if the 'buildTarget' option is not specified."
"x-priority": "important"
},
"main": {
"type": "string",
"description": "Provide a different entry point than what is specified in the buildTarget"
"description": "Provide a different entry point than what is specified in the 'buildTarget'. This option is required if the 'buildTarget' option is not specified."
"x-priority": "important"
},
"cert": {
"type": "string",
"description": "Load certificate authority from PEM encoded file."
},
"check": {
"anyOf": [{ "type": "boolean" }, { "type": "string" }],
"oneOf": [{ "type": "boolean" }, { "type": "string" }],
"description": "Type-check modules. Deno does not type-check modules automatically from v1.23 onwards. Set this option to enable type-checking or use the 'deno check' subcommand. If the value of '--check=all' is supplied, diagonstic errors from remote modules will be included.",
"enum": ["none", "local", "all"],
"default": "local"
"default": "local",
"x-priority": "important"
},

"inspect": {
"description": "Activate inspector on host:port, wait for debugger to connect before running user code. Defaults to 127.0.0.1:9229 if no host:port is provided",
"anyOf": [
"oneOf": [
{
"type": "boolean"
},
Expand Down Expand Up @@ -71,7 +74,7 @@
},
"reload": {
"description": "Reload source code cache (recompile TypeScript)",
"anyOf": [
"oneOf": [
{
"type": "boolean"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import {
parseTargetString,
readTargetOptions,
} from '@nrwl/devkit';
import { processTypeCheckOption } from '../../utils/arg-utils';
import { runDeno } from '../../utils/run-deno';
import { BuildExecutorSchema } from '../build/schema';
import { ServeExecutorSchema } from './schema';

export default async function* runExecutor(
export async function* denoServeExecutor(
options: ServeExecutorSchema,
context: ExecutorContext
) {
const opts = normalizeOptions(options, context);
const args = createArgs(opts);

const runningDenoProcess = runDeno(args);
// TODO(chau): does process need to be handled differently like @nrwl/js?

yield { success: true };

Expand All @@ -26,22 +28,29 @@ function normalizeOptions(
options: ServeExecutorSchema,
context: ExecutorContext
) {
const target = parseTargetString(options.buildTarget);
const buildTargetOptions = readTargetOptions<BuildExecutorSchema>(
target,
context
);
const mergedOptions = {
...buildTargetOptions,
...options,
};
let mergedOptions: ServeExecutorSchema;
if (options.buildTarget) {
const target = parseTargetString(options.buildTarget, context.projectGraph);
const buildTargetOptions = readTargetOptions<BuildExecutorSchema>(
target,
context
);
mergedOptions = {
...buildTargetOptions,
...options,
};
}

if (!mergedOptions.main) {
throw new Error('main is required');
throw new Error(
'Missing "main" property as apart of the executor options. Please specify the "main" property in the executor options or specify a buildTarget that has a valid "main" property defined.'
);
}

if (!mergedOptions.denoConfig) {
throw new Error('denoConfig is required');
throw new Error(
'Missing "denoConfig" property as apart of the executor options. Please specify the "denoConfig" property in the executor options or specify a buildTarget that has a valid "denoConfig" property defined.'
);
}

return mergedOptions;
Expand All @@ -55,23 +64,9 @@ function createArgs(options: ServeExecutorSchema) {
args.push(`--cert=${options.cert}`);
}
if (options.check !== undefined) {
// TODO(caleb): why are boolean args being parsed as strings?
if (
options.check === 'none' ||
options.check === false ||
options.check === 'false'
) {
args.push('--no-check');
} else if (
options.check === 'local' ||
options.check === true ||
options.check === 'true'
) {
args.push('--check');
} else if (options.check === 'all') {
args.push('--check=all');
}
args.push(processTypeCheckOption(options.check));
}

if (options.inspect) {
args.push(
`--inspect-brk=${
Expand Down Expand Up @@ -124,3 +119,5 @@ function createArgs(options: ServeExecutorSchema) {

return args;
}

export default denoServeExecutor;
2 changes: 1 addition & 1 deletion packages/deno/src/executors/test/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DenoTypeCheck } from '../../utils/schema-types';
import { DenoTypeCheck } from '../../utils/arg-utils';

export interface DenoTestExecutorSchema {
denoConfig: string;
Expand Down
Loading

0 comments on commit 9fde27e

Please sign in to comment.