From 6c21a4b9500bc5807db9e04455d14dd0d917ef92 Mon Sep 17 00:00:00 2001 From: Sean Ryan Date: Sat, 10 Dec 2022 20:25:34 +0100 Subject: [PATCH] Add support for js index file - #219 (#251) Add itest to cover use of JS files --- example/with-js/.gitignore | 1 + example/with-js/package-lock.json | 14 ++++++++++++++ example/with-js/package.json | 14 ++++++++++++++ example/with-js/src/Component/Component.js | 2 ++ example/with-js/src/Game/Entity.ts | 5 +++++ example/with-js/src/Game/Player.js | 2 ++ example/with-js/src/comp.tsx | 6 ++++++ example/with-js/src/index.ts | 7 +++++++ example/with-js/src/unused.ts | 1 + example/with-js/src/util.ts | 2 ++ example/with-js/tsconfig.json | 15 +++++++++++++++ ispec/run.sh | 4 ++++ 12 files changed, 73 insertions(+) create mode 100644 example/with-js/.gitignore create mode 100644 example/with-js/package-lock.json create mode 100644 example/with-js/package.json create mode 100644 example/with-js/src/Component/Component.js create mode 100644 example/with-js/src/Game/Entity.ts create mode 100644 example/with-js/src/Game/Player.js create mode 100644 example/with-js/src/comp.tsx create mode 100644 example/with-js/src/index.ts create mode 100644 example/with-js/src/unused.ts create mode 100644 example/with-js/src/util.ts create mode 100644 example/with-js/tsconfig.json diff --git a/example/with-js/.gitignore b/example/with-js/.gitignore new file mode 100644 index 00000000..378eac25 --- /dev/null +++ b/example/with-js/.gitignore @@ -0,0 +1 @@ +build diff --git a/example/with-js/package-lock.json b/example/with-js/package-lock.json new file mode 100644 index 00000000..005e0782 --- /dev/null +++ b/example/with-js/package-lock.json @@ -0,0 +1,14 @@ +{ + "name": "with-js", + "version": "0.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "typescript": { + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", + "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "dev": true + } + } +} diff --git a/example/with-js/package.json b/example/with-js/package.json new file mode 100644 index 00000000..cb4d027b --- /dev/null +++ b/example/with-js/package.json @@ -0,0 +1,14 @@ +{ + "name": "with-js", + "version": "0.0.0", + "description": "Example used by integration tests (ispec) - with-js", + "main": "src/index.js", + "scripts": { + "build": "tsc --allowJs", + "test": "tsc --allowJs && ../../bin/ts-unused-exports tsconfig.json" + }, + "license": "MIT", + "devDependencies": { + "typescript": "^4.7.4" + } +} diff --git a/example/with-js/src/Component/Component.js b/example/with-js/src/Component/Component.js new file mode 100644 index 00000000..56e56705 --- /dev/null +++ b/example/with-js/src/Component/Component.js @@ -0,0 +1,2 @@ +export function Component() { +} \ No newline at end of file diff --git a/example/with-js/src/Game/Entity.ts b/example/with-js/src/Game/Entity.ts new file mode 100644 index 00000000..fbd67f91 --- /dev/null +++ b/example/with-js/src/Game/Entity.ts @@ -0,0 +1,5 @@ +import { Component } from '../Component/Component.js' + +export class Entity +{ +} \ No newline at end of file diff --git a/example/with-js/src/Game/Player.js b/example/with-js/src/Game/Player.js new file mode 100644 index 00000000..3a1ab951 --- /dev/null +++ b/example/with-js/src/Game/Player.js @@ -0,0 +1,2 @@ +export function Player() { +} \ No newline at end of file diff --git a/example/with-js/src/comp.tsx b/example/with-js/src/comp.tsx new file mode 100644 index 00000000..6f696b31 --- /dev/null +++ b/example/with-js/src/comp.tsx @@ -0,0 +1,6 @@ +import * as React from 'react'; +import { thisOneIsUsed } from './util'; + +const Comp = ({ a }: { a: string }) =>
{thisOneIsUsed}{a}
; + +console.log(Comp); \ No newline at end of file diff --git a/example/with-js/src/index.ts b/example/with-js/src/index.ts new file mode 100644 index 00000000..eb14baf9 --- /dev/null +++ b/example/with-js/src/index.ts @@ -0,0 +1,7 @@ +import { Entity } from './Game/Entity' +import { Player } from './Game/Player.js' +import { thisOneIsUsed } from "./util" + +console.log(`Entity: ${Entity}`) +console.log(`Player: ${Player}`) +console.log(`thisOneIsUsed: ${thisOneIsUsed}`) diff --git a/example/with-js/src/unused.ts b/example/with-js/src/unused.ts new file mode 100644 index 00000000..436738be --- /dev/null +++ b/example/with-js/src/unused.ts @@ -0,0 +1 @@ +export const thisOneIsNotUsed = 2; \ No newline at end of file diff --git a/example/with-js/src/util.ts b/example/with-js/src/util.ts new file mode 100644 index 00000000..91da2056 --- /dev/null +++ b/example/with-js/src/util.ts @@ -0,0 +1,2 @@ +export const thisOneIsUsed = 1; +export const thisOneIsNotUsed = 2; \ No newline at end of file diff --git a/example/with-js/tsconfig.json b/example/with-js/tsconfig.json new file mode 100644 index 00000000..7afa20ad --- /dev/null +++ b/example/with-js/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "module": "es6", + "target": "es2019", + "noImplicitAny": false, + "alwaysStrict": true, + "removeComments": true, + "strictNullChecks": true, + "preserveConstEnums": true, + "sourceMap": true, + "outDir": "build" + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules"] + } \ No newline at end of file diff --git a/ispec/run.sh b/ispec/run.sh index 6eec5c16..498e85e3 100755 --- a/ispec/run.sh +++ b/ispec/run.sh @@ -79,5 +79,9 @@ pushd ../example/path-alias-and-sub-folders run_itest popd +pushd ../example/with-js +run_itest +popd + # Test running from another directory ./_run_from_directory_not_project.sh