From 832922c9593d30d21606e71a1d02e614955ec9ac Mon Sep 17 00:00:00 2001 From: Vignesh Date: Tue, 10 Jul 2018 14:00:12 +0800 Subject: [PATCH] Make the repo an NPM package (#9) * Change main file to index.ts * Change main to pre-defined index * Add index file at root This is to allow 'slang' imports. The rootDir has been changed to '.' since the index file exists here. In addition, the main file in package.json has been changed to the root index file. * Change index to src/index This is because we will be exporting everything to the /dist directory anyways. * Add types export for tsconfig Allows exporting types for the built files. Also changed rootDir * Fix shadowing name error When building, the Error type returned could also refer to Error defined in node. So, I explicitly defined the return type. * Change properties for publishing - Change main and typings - Add files to be included in publishing - Add pre-publish script * Use types property Typings will be deprecated * Change name and author * Add organization name --- package.json | 16 +++++++++++----- src/index.ts | 4 ++-- src/types.ts | 2 +- tsconfig.json | 4 +++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index d5f07083b..f0014c4da 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,11 @@ { - "name": "slang", + "name": "@source-academy/js-slang", "version": "0.1.0", "description": "Javascript-based interpreter for slang, written in Typescript", + "author": { + "name" : "Source Academy", + "url" : "https://github.com/source-academy/" + }, "dependencies": { "acorn": "^5.7.1", "astring": "^1.2.0", @@ -9,11 +13,13 @@ "common-tags": "^1.4.0", "invariant": "^2.2.2" }, - "main": "slang.js", - "bin": { - "slang": "slang.js" - }, + "main": "dist/index", + "types": "dist/index", + "files": [ + "dist" + ], "scripts": { + "prepublishOnly": "tsc", "build": "tsc", "test": "jest" }, diff --git a/src/index.ts b/src/index.ts index bf2c1e00b..5f1b4707a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import { evaluate } from './interpreter' import { InterruptedError } from './interpreter-errors' import { parse } from './parser' import { AsyncScheduler, PreemptiveScheduler } from './schedulers' -import { Context, Result, Scheduler, SourceError } from './types' +import { Context, Error, Finished, Result, Scheduler, SourceError } from './types' export interface IOptions { scheduler: 'preemptive' | 'async' @@ -47,7 +47,7 @@ export function runInContext( } } -export function resume(result: Result) { +export function resume(result: Result): Finished | Error | Promise { if (result.status === 'finished' || result.status === 'error') { return result } else { diff --git a/src/types.ts b/src/types.ts index aa98929e4..8424709fe 100644 --- a/src/types.ts +++ b/src/types.ts @@ -191,7 +191,7 @@ export class ArrowClosure { } } -interface Error { +export interface Error { status: 'error' } diff --git a/tsconfig.json b/tsconfig.json index 5a8532ca5..9b827b7c5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "outDir": "./dist", "module": "CommonJS", + "declaration": true, "target": "es2016", "lib": [ "es2017.object", @@ -24,7 +25,8 @@ "noUnusedLocals": true }, "exclude": [ - "node_modules" + "node_modules", + "dist" ], "types": [ "typePatches"