Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaringe committed Mar 12, 2022
1 parent 4ce39df commit 55fc9e9
Show file tree
Hide file tree
Showing 27 changed files with 344 additions and 5 deletions.
18 changes: 18 additions & 0 deletions apps/dummy/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
15 changes: 15 additions & 0 deletions apps/dummy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# dummy

This application was generated with [Nx](https://nx.dev).

## Building

Run `nx build dummy` to build the application.

## Starting

Run `nx start dummy` to start/run the application.

## Running unit tests

Run `nx test dummy` to execute the unit tests via [Jest](https://jestjs.io).
14 changes: 14 additions & 0 deletions apps/dummy/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
displayName: 'dummy',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/dummy',
};
5 changes: 5 additions & 0 deletions apps/dummy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@nx-example/dummy",
"version": "0.0.1",
"type": "commonjs"
}
39 changes: 39 additions & 0 deletions apps/dummy/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"root": "apps/dummy",
"sourceRoot": "apps/dummy/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/dummy",
"main": "apps/dummy/src/index.ts",
"tsConfig": "apps/dummy/tsconfig.app.json",
"assets": ["apps/dummy/*.md"]
}
},
"serve": {
"executor": "@nrwl/js:node",
"options": {
"buildTarget": "dummy:build"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/dummy/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/dummy"],
"options": {
"jestConfig": "apps/dummy/jest.config.js",
"passWithNoTests": true
}
}
},
"tags": []
}
7 changes: 7 additions & 0 deletions apps/dummy/src/app/dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// eslint-disable-next-line no-eval
const argv = eval('process').argv as string[];
export function dummy() {
setInterval(() => {
console.log(argv.slice(2));
}, 1000);
}
2 changes: 2 additions & 0 deletions apps/dummy/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { dummy } from './app/dummy';
dummy();
10 changes: 10 additions & 0 deletions apps/dummy/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": []
},
"include": ["**/*.ts"],
"exclude": ["**/*.spec.ts"]
}
22 changes: 22 additions & 0 deletions apps/dummy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "CommonJS",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions apps/dummy/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
3 changes: 3 additions & 0 deletions libs/foo/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]]
}
18 changes: 18 additions & 0 deletions libs/foo/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/foo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# foo

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test foo` to execute the unit tests via [Jest](https://jestjs.io).
14 changes: 14 additions & 0 deletions libs/foo/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
displayName: 'foo',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/foo',
};
13 changes: 13 additions & 0 deletions libs/foo/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"root": "libs/foo",
"sourceRoot": "libs/foo/src",
"projectType": "library",
"targets": {
"baz": {
"executor": "./libs/foo/src/executors:bar",
"outputs": ["{options.outputFile}"],
"options": {}
}
},
"tags": []
}
32 changes: 32 additions & 0 deletions libs/foo/src/executors/bar/combine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = async function* combine(iterable) {
const asyncIterators = Array.from(iterable, (o) => o[Symbol.asyncIterator]());
const results = [];
let count = asyncIterators.length;
const never = new Promise(() => {});
function getNext(asyncIterator, index) {
return asyncIterator.next().then((result) => ({
index,
result,
}));
}
const nextPromises = asyncIterators.map(getNext);
try {
while (count) {
const { index, result } = await Promise.race(nextPromises);
if (result.done) {
nextPromises[index] = never;
results[index] = result.value;
count--;
} else {
nextPromises[index] = getNext(asyncIterators[index], index);
yield result.value;
}
}
} finally {
for (const [index, iterator] of asyncIterators.entries())
if (nextPromises[index] != never && iterator.return != null)
iterator.return();
// no await here - see https://github.com/tc39/proposal-async-iteration/issues/126
}
return results;
};
42 changes: 42 additions & 0 deletions libs/foo/src/executors/bar/impl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { runExecutor } = require('@nrwl/devkit');
const combine = require('./combine');

module.exports = {
/**
* This is executor is what does not work.
* I cannot run two `runExecutor`s at the same time
* using the js:serve executor.
*
* Observe that APP_1 never emits anything. This is
* incorrect behavior.
*
* Try:
* - changing the target to `build` - works!
*
*
*/
default: async function* fooExecutor(_options, ctx) {
const asyncIterators = await Promise.all([
runExecutor(
{
target: 'serve',
project: 'dummy',
},
{ args: 'APP_1' },
ctx
),
runExecutor(
{
target: 'serve',
project: 'dummy',
},
{ args: 'APP_2' },
ctx
),
]);
for await (const evt of combine(asyncIterators)) {
yield evt;
}
return { success: true };
},
};
6 changes: 6 additions & 0 deletions libs/foo/src/executors/bar/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/schema",
"type": "object",
"cli": "nx",
"properties": {}
}
9 changes: 9 additions & 0 deletions libs/foo/src/executors/executor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"executors": {
"bar": {
"implementation": "./bar/impl",
"schema": "./bar/schema.json",
"description": ""
}
}
}
3 changes: 3 additions & 0 deletions libs/foo/src/executors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"executors": "./executor.json"
}
19 changes: 19 additions & 0 deletions libs/foo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
}
10 changes: 10 additions & 0 deletions libs/foo/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": []
},
"include": ["**/*.ts"],
"exclude": ["**/*.spec.ts"]
}
19 changes: 19 additions & 0 deletions libs/foo/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.test.tsx",
"**/*.spec.tsx",
"**/*.test.js",
"**/*.spec.js",
"**/*.test.jsx",
"**/*.spec.jsx",
"**/*.d.ts"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@nrwl/workspace": "13.8.1",
"@testing-library/react": "11.2.6",
"@types/jest": "27.0.2",
"@types/node": "14.14.33",
"@types/node": "17.0.21",
"@types/react": "17.0.3",
"@types/react-dom": "17.0.3",
"@types/react-router-dom": "5.1.7",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"baseUrl": ".",
"paths": {
"@nx-example/cart/cart-page": ["libs/cart/cart-page/src/index.ts"],
"@nx-example/foo": ["libs/foo/src/index.ts"],
"@nx-example/products/home-page": [
"libs/products/home-page/src/index.ts"
],
Expand Down
2 changes: 2 additions & 0 deletions workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"cart": "apps/cart",
"cart-cart-page": "libs/cart/cart-page",
"cart-e2e": "apps/cart-e2e",
"dummy": "apps/dummy",
"foo": "libs/foo",
"products": "apps/products",
"products-e2e": "apps/products-e2e",
"products-home-page": "libs/products/home-page",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3804,10 +3804,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.7.10.tgz#7aa732cc47341c12a16b7d562f519c2383b6d4fc"
integrity sha512-S63Dlv4zIPb8x6MMTgDq5WWRJQe56iBEY0O3SOFA9JrRienkOVDXSXBjjJw6HTNQYSE2JI6GMCR6LVbIMHJVvA==

"@types/node@14.14.33":
version "14.14.33"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.33.tgz#9e4f8c64345522e4e8ce77b334a8aaa64e2b6c78"
integrity sha512-oJqcTrgPUF29oUP8AsUqbXGJNuPutsetaa9kTQAQce5Lx5dTYWV02ScBiT/k1BX/Z7pKeqedmvp39Wu4zR7N7g==
"@types/node@17.0.21":
version "17.0.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.21.tgz#864b987c0c68d07b4345845c3e63b75edd143644"
integrity sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==

"@types/node@^14.14.31":
version "14.17.14"
Expand Down

0 comments on commit 55fc9e9

Please sign in to comment.