Skip to content

Commit

Permalink
fix(paths): Refactor Paths handling (#80)
Browse files Browse the repository at this point in the history
* fix(paths): Refactor paths handling to suport js along with plain non path paths

* tests(js,ts): Add extension and extensionless path tests

* chore(names): rename debugging const
  • Loading branch information
EntraptaJ authored May 27, 2020
1 parent e6a4ab6 commit e537269
Show file tree
Hide file tree
Showing 33 changed files with 366 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Testing/Tests/JSNonExtPaths/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Testing/Tests/JSNonExtPaths/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "js-nonextpaths",
"type": "module",
"main": "./src/index.ts",
"NODE_OPTIONS": "--harmony-top-level-await",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node --loader ../../../out/dist/index.js --experimental-specifier-resolution=node --experimental-import-meta-resolve --harmony-optional-chaining --harmony-top-level-await src/index.ts"
},
"author": "",
"license": "ISC"
}
6 changes: 6 additions & 0 deletions Testing/Tests/JSNonExtPaths/src/Module/HelloWorld/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/src/Module/HelloWorld/index.ts
import { add } from '@paths/Utils/Math';

export async function testingSubPath(): Promise<number> {
return add(1, 5);
}
6 changes: 6 additions & 0 deletions Testing/Tests/JSNonExtPaths/src/Module/Random/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/JSPaths/src/Module/Random/index.ts
import { sayRandom } from 'random';

export async function randomModule(): Promise<string> {
return sayRandom();
}
13 changes: 13 additions & 0 deletions Testing/Tests/JSNonExtPaths/src/Utils/Math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Testing/Tests/Lab/src/Utils/Math.ts

export function add(x: number, y: number): number {
console.debug(`Adding ${x} + ${y}`);

return x + y;
}

export function divide(x: number, y: number): number {
console.debug(`Dividing ${x} / ${y}`);

return x / y;
}
4 changes: 4 additions & 0 deletions Testing/Tests/JSNonExtPaths/src/Utils/random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Testing/Tests/JSPaths/src/Utils/random.js
export function sayRandom() {
return 'random';
}
27 changes: 27 additions & 0 deletions Testing/Tests/JSNonExtPaths/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Testing/Tests/Lab/src/index.ts
import { add, divide } from '@paths/Utils/Math';
import { strictEqual } from 'assert';

export async function startApp(): Promise<void> {
console.debug('Starting Application');

const sum = add(1, 1);
strictEqual(sum, 2);

const divideResult = divide(2, 2);
strictEqual(divideResult, 1);

const { testingSubPath } = await import('@paths/Module/HelloWorld');

const addSub = await testingSubPath();
strictEqual(addSub, 6);

const { randomModule } = await import('@paths/Module/Random');

const randomResult = await randomModule();
strictEqual(randomResult, 'random');

console.debug('Done');
}

startApp();
15 changes: 15 additions & 0 deletions Testing/Tests/JSNonExtPaths/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",

"allowJs": true,
"paths": {
"@paths/*": ["./*"],
"random": ["./Utils/random"]
}
}
}
4 changes: 4 additions & 0 deletions Testing/Tests/JSPaths/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Testing/Tests/JSPaths/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "js-paths",
"type": "module",
"main": "./src/index.ts",
"NODE_OPTIONS": "--harmony-top-level-await",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node --loader ../../../out/dist/index.js --experimental-specifier-resolution=node --experimental-import-meta-resolve --harmony-optional-chaining --harmony-top-level-await src/index.ts"
},
"author": "",
"license": "ISC"
}
6 changes: 6 additions & 0 deletions Testing/Tests/JSPaths/src/Module/HelloWorld/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/src/Module/HelloWorld/index.ts
import { add } from '@paths/Utils/Math';

export async function testingSubPath(): Promise<number> {
return add(1, 5);
}
6 changes: 6 additions & 0 deletions Testing/Tests/JSPaths/src/Module/Random/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/JSPaths/src/Module/Random/index.ts
import { sayRandom } from 'random';

export async function randomModule(): Promise<string> {
return sayRandom();
}
13 changes: 13 additions & 0 deletions Testing/Tests/JSPaths/src/Utils/Math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Testing/Tests/Lab/src/Utils/Math.ts

export function add(x: number, y: number): number {
console.debug(`Adding ${x} + ${y}`);

return x + y;
}

export function divide(x: number, y: number): number {
console.debug(`Dividing ${x} / ${y}`);

return x / y;
}
4 changes: 4 additions & 0 deletions Testing/Tests/JSPaths/src/Utils/random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Testing/Tests/JSPaths/src/Utils/random.js
export function sayRandom() {
return 'random';
}
27 changes: 27 additions & 0 deletions Testing/Tests/JSPaths/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Testing/Tests/Lab/src/index.ts
import { add, divide } from '@paths/Utils/Math';
import { strictEqual } from 'assert';

export async function startApp(): Promise<void> {
console.debug('Starting Application');

const sum = add(1, 1);
strictEqual(sum, 2);

const divideResult = divide(2, 2);
strictEqual(divideResult, 1);

const { testingSubPath } = await import('@paths/Module/HelloWorld');

const addSub = await testingSubPath();
strictEqual(addSub, 6);

const { randomModule } = await import('@paths/Module/Random');

const randomResult = await randomModule();
strictEqual(randomResult, 'random');

console.debug('Done');
}

startApp();
15 changes: 15 additions & 0 deletions Testing/Tests/JSPaths/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",

"allowJs": true,
"paths": {
"@paths/*": ["./*"],
"random": ["./Utils/random.js"]
}
}
}
4 changes: 4 additions & 0 deletions Testing/Tests/TSExtPaths/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Testing/Tests/TSExtPaths/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "ts-extpaths",
"type": "module",
"main": "./src/index.ts",
"NODE_OPTIONS": "--harmony-top-level-await",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node --loader ../../../out/dist/index.js --experimental-specifier-resolution=node --experimental-import-meta-resolve --harmony-optional-chaining --harmony-top-level-await src/index.ts"
},
"author": "",
"license": "ISC"
}
6 changes: 6 additions & 0 deletions Testing/Tests/TSExtPaths/src/Module/HelloWorld/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/src/Module/HelloWorld/index.ts
import { add } from '@paths/Utils/Math';

export async function testingSubPath(): Promise<number> {
return add(1, 5);
}
6 changes: 6 additions & 0 deletions Testing/Tests/TSExtPaths/src/Module/Random/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/JSPaths/src/Module/Random/index.ts
import { sayRandom } from 'random';

export async function randomModule(): Promise<string> {
return sayRandom();
}
13 changes: 13 additions & 0 deletions Testing/Tests/TSExtPaths/src/Utils/Math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Testing/Tests/Lab/src/Utils/Math.ts

export function add(x: number, y: number): number {
console.debug(`Adding ${x} + ${y}`);

return x + y;
}

export function divide(x: number, y: number): number {
console.debug(`Dividing ${x} / ${y}`);

return x / y;
}
4 changes: 4 additions & 0 deletions Testing/Tests/TSExtPaths/src/Utils/random.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Testing/Tests/JSPaths/src/Utils/random.js
export function sayRandom(): 'random' {
return 'random';
}
29 changes: 29 additions & 0 deletions Testing/Tests/TSExtPaths/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Testing/Tests/Lab/src/index.ts
import { add, divide } from '@paths/Utils/Math';
import { strictEqual } from 'assert';

export async function startApp(): Promise<void> {
console.debug('Starting Application');

const sum = add(1, 1);
strictEqual(sum, 2);

const divideResult = divide(2, 2);
strictEqual(divideResult, 1);

const { testingSubPath } = await import('@paths/Module/HelloWorld');

const addSub = await testingSubPath();
strictEqual(addSub, 6);

const { randomModule } = await import('@paths/Module/Random');

const randomResult = await randomModule();
console.log('randomResult: ', randomResult);

strictEqual(randomResult, 'random');

console.debug('Done');
}

startApp();
15 changes: 15 additions & 0 deletions Testing/Tests/TSExtPaths/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",

"allowJs": true,
"paths": {
"@paths/*": ["./*"],
"random": ["./Utils/random.ts"]
}
}
}
4 changes: 4 additions & 0 deletions Testing/Tests/TSNonExtPaths/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Testing/Tests/TSNonExtPaths/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "ts-nonextpaths",
"type": "module",
"main": "./src/index.ts",
"NODE_OPTIONS": "--harmony-top-level-await",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node --loader ../../../out/dist/index.js --experimental-specifier-resolution=node --experimental-import-meta-resolve --harmony-optional-chaining --harmony-top-level-await src/index.ts"
},
"author": "",
"license": "ISC"
}
6 changes: 6 additions & 0 deletions Testing/Tests/TSNonExtPaths/src/Module/HelloWorld/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/src/Module/HelloWorld/index.ts
import { add } from '@paths/Utils/Math';

export async function testingSubPath(): Promise<number> {
return add(1, 5);
}
6 changes: 6 additions & 0 deletions Testing/Tests/TSNonExtPaths/src/Module/Random/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/JSPaths/src/Module/Random/index.ts
import { sayRandom } from 'random';

export async function randomModule(): Promise<string> {
return sayRandom();
}
13 changes: 13 additions & 0 deletions Testing/Tests/TSNonExtPaths/src/Utils/Math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Testing/Tests/Lab/src/Utils/Math.ts

export function add(x: number, y: number): number {
console.debug(`Adding ${x} + ${y}`);

return x + y;
}

export function divide(x: number, y: number): number {
console.debug(`Dividing ${x} / ${y}`);

return x / y;
}
4 changes: 4 additions & 0 deletions Testing/Tests/TSNonExtPaths/src/Utils/random.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Testing/Tests/JSPaths/src/Utils/random.js
export function sayRandom(): 'random' {
return 'random';
}
29 changes: 29 additions & 0 deletions Testing/Tests/TSNonExtPaths/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Testing/Tests/Lab/src/index.ts
import { add, divide } from '@paths/Utils/Math';
import { strictEqual } from 'assert';

export async function startApp(): Promise<void> {
console.debug('Starting Application');

const sum = add(1, 1);
strictEqual(sum, 2);

const divideResult = divide(2, 2);
strictEqual(divideResult, 1);

const { testingSubPath } = await import('@paths/Module/HelloWorld');

const addSub = await testingSubPath();
strictEqual(addSub, 6);

const { randomModule } = await import('@paths/Module/Random');

const randomResult = await randomModule();
console.log('randomResult: ', randomResult);

strictEqual(randomResult, 'random');

console.debug('Done');
}

startApp();
15 changes: 15 additions & 0 deletions Testing/Tests/TSNonExtPaths/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",

"allowJs": true,
"paths": {
"@paths/*": ["./*"],
"random": ["./Utils/random"]
}
}
}
Loading

0 comments on commit e537269

Please sign in to comment.