-
Notifications
You must be signed in to change notification settings - Fork 156
Add build step and TS support #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| bower_components | ||
| node_modules | ||
| coverage* | ||
| coverage* | ||
| dist | ||
| src/pretender.es.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| src/index.ts | ||
| test | ||
| rollup.config.js | ||
| karma.conf.js | ||
| *.md | ||
| yarn.lock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,24 @@ | ||
| { | ||
| "name": "pretender", | ||
| "version": "2.1.0", | ||
| "main": "./pretender.js", | ||
| "main": "./dist/pretender.js", | ||
| "module": "./src/pretender.es.js", | ||
| "types": "index.d.ts", | ||
| "description": "Pretender is a mock server library for XMLHttpRequest and Fetch, that comes with an express/sinatra style syntax for defining routes and their handlers.", | ||
| "license": "MIT", | ||
| "engines": { | ||
| "node": "6.* || 8.* || 10.* || >= 11.*" | ||
| }, | ||
| "scripts": { | ||
| "prepublishOnly": "npm run build && npm run tests-only", | ||
| "pretest": "bower install", | ||
| "build": "rollup --config", | ||
| "test": "npm run lint && npm run jscs && npm run tests-only", | ||
| "test-ci": "npm run pretest && npm run lint && npm run jscs && npm run tests-only-ci", | ||
| "test-ci": "npm run pretest && npm run build && npm run lint && npm run jscs && npm run tests-only-ci", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making sure that the build step is ran before running the tests, in case there is a PR that didn't include the build outputs. |
||
| "tests-only": "karma start --single-run", | ||
| "tests-only-ci": "karma start --single-run --browsers PhantomJS", | ||
| "lint": "jshint pretender.js test", | ||
| "jscs": "jscs pretender.js test", | ||
| "lint": "jshint test", | ||
| "jscs": "jscs test", | ||
| "test:server": "karma start --no-single-run" | ||
| }, | ||
| "repository": { | ||
|
|
@@ -36,7 +40,14 @@ | |
| "karma-sinon": "^1.0.5", | ||
| "phantomjs": "^2.1.7", | ||
| "qunit": "^2.6.1", | ||
| "sinon": "^3.2.1" | ||
| "rollup": "0.68.2", | ||
| "rollup-plugin-commonjs": "^9.2.0", | ||
| "rollup-plugin-multi-entry": "^2.1.0", | ||
| "rollup-plugin-node-resolve": "^4.0.0", | ||
| "rollup-plugin-typescript": "^1.0.0", | ||
| "sinon": "^3.2.1", | ||
| "tslib": "^1.9.3", | ||
mike-north marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "typescript": "~3.1.1" | ||
| }, | ||
| "dependencies": { | ||
| "whatwg-fetch": "^3.0.0", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| const commonjs = require('rollup-plugin-commonjs'); | ||
| const path = require('path'); | ||
| const resolve = require('rollup-plugin-node-resolve'); | ||
| const typescript = require('rollup-plugin-typescript'); | ||
| const pkg = require('./package.json'); | ||
|
|
||
| const selfId = path.resolve(__dirname, 'src/iife-self-placeholder.js'); | ||
|
|
||
| module.exports = { | ||
| input: 'src/index.ts', | ||
| external: [ | ||
| selfId, | ||
| 'whatwg-fetch', | ||
| 'fake-xml-http-request', | ||
| 'route-recognizer', | ||
| ], | ||
| output: [ | ||
| { | ||
| name: 'Pretender', | ||
| file: pkg.main, | ||
| format: 'iife', | ||
| globals: { | ||
| [selfId]: 'self', | ||
| 'whatwg-fetch': 'FakeFetch', | ||
| 'fake-xml-http-request': 'FakeXMLHttpRequest', | ||
| 'route-recognizer': 'RouteRecognizer', | ||
| }, | ||
| banner: 'var FakeFetch = self.WHATWGFetch;\n' + | ||
| 'var FakeXMLHttpRequest = self.FakeXMLHttpRequest;\n' + | ||
| 'var RouteRecognizer = self.RouteRecognizer;\n', | ||
| }, | ||
| { | ||
| file: pkg.module, | ||
| format: 'es' | ||
| }, | ||
| ], | ||
| plugins: [ | ||
| commonjs(), | ||
| resolve(), | ||
| typescript() | ||
| ], | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // This is just a placeholder for the build step | ||
| // See the IIFE output in the Rollup config | ||
| export default window; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,7 @@ | ||
| (function(self) { | ||
| 'use strict'; | ||
|
|
||
| function getModuleDefault(module) { | ||
| return module.default || module; | ||
| } | ||
|
|
||
| var appearsBrowserified = typeof self !== 'undefined' && | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a breaking change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't break anyones app. The build step produces two files with unique consumption mechanisms that immediately inform whether you are browserifying or not depending on which one you choose to use. So, Pretender doesn't need to figure that out at runtime anymore. |
||
| typeof process !== 'undefined' && | ||
| (Object.prototype.toString.call(process) === '[object Object]' || | ||
| Object.prototype.toString.call(process) === '[object process]'); | ||
|
|
||
| var RouteRecognizer = appearsBrowserified ? getModuleDefault(require('route-recognizer')) : self.RouteRecognizer; | ||
| var FakeXMLHttpRequest = appearsBrowserified ? getModuleDefault(require('fake-xml-http-request')) : | ||
| self.FakeXMLHttpRequest; | ||
|
|
||
| // fetch related ponyfills | ||
| var FakeFetch = appearsBrowserified ? getModuleDefault(require('whatwg-fetch')) : self.WHATWGFetch; | ||
| import self from './iife-self-placeholder'; | ||
| import RouteRecognizer from 'route-recognizer'; | ||
| import FakeXMLHttpRequest from 'fake-xml-http-request'; | ||
| import * as FakeFetch from 'whatwg-fetch'; | ||
|
|
||
| /** | ||
| * parseURL - decompose a URL into its parts | ||
|
|
@@ -495,12 +481,4 @@ Pretender.parseURL = parseURL; | |
| Pretender.Hosts = Hosts; | ||
| Pretender.Registry = Registry; | ||
|
|
||
| if (typeof module === 'object') { | ||
| module.exports = Pretender; | ||
| } else if (typeof define !== 'undefined') { | ||
| define('pretender', [], function() { | ||
| return Pretender; | ||
| }); | ||
| } | ||
| self.Pretender = Pretender; | ||
| }(self)); | ||
| export default Pretender; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| { | ||
| "compilerOptions": { | ||
| /* Basic Options */ | ||
| "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ | ||
| "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
| // "lib": [], /* Specify library files to be included in the compilation. */ | ||
| // "allowJs": true, /* Allow javascript files to be compiled. */ | ||
| // "checkJs": true, /* Report errors in .js files. */ | ||
| "declaration": false, /* Generates corresponding '.d.ts' file. */ | ||
mike-north marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
| // "sourceMap": true, /* Generates corresponding '.map' file. */ | ||
| // "outFile": "./", /* Concatenate and emit output to single file. */ | ||
| // "outDir": "./", /* Redirect output structure to the directory. */ | ||
| // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
| // "composite": true, /* Enable project compilation */ | ||
| // "removeComments": true, /* Do not emit comments to output. */ | ||
| "noEmit": true, /* Do not emit outputs. */ | ||
| // "importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
| // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
| // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ | ||
|
|
||
| "newLine": "LF", | ||
|
|
||
| /* Strict Type-Checking Options */ | ||
| "strict": true, /* Enable all strict type-checking options. */ | ||
| "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
| // "strictNullChecks": true, /* Enable strict null checks. */ | ||
| // "strictFunctionTypes": true, /* Enable strict checking of function types. */ | ||
| // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ | ||
| // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ | ||
| // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ | ||
|
|
||
| /* Additional Checks */ | ||
| "noUnusedLocals": true, /* Report errors on unused locals. */ | ||
| "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
| "noImplicitReturns": false, /* Report error when not all code paths in function return a value. */ | ||
| "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
|
|
||
| /* Module Resolution Options */ | ||
| "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ | ||
| // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ | ||
| // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ | ||
| // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ | ||
| // "typeRoots": [], /* List of folders to include type definitions from. */ | ||
| // "types": [], /* Type declaration files to be included in compilation. */ | ||
| // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ | ||
| "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
| // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
|
|
||
| /* Source Map Options */ | ||
| // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ | ||
| // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ | ||
| // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ | ||
| // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ | ||
|
|
||
| /* Experimental Options */ | ||
| // "experimentalDecorators": false, /* Enables experimental support for ES7 decorators. */ | ||
| // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making sure that the build step is ran before publishing a new version, in case a PR bypassed a red CI somehow.