npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typescript-middleware

v0.6.10

Published

typescript auto compile connect-middleware.

Downloads

47

Readme

What's this

The on the fly typescript compile server for express/connect.

Install

npm install typescript-middleware

Usage

var tscMiddleware = require('typescript-middleware');
var connect = require('connect');
var app = connect();
app.use('typescript', tscMiddleware({
  outDir: 'js/out', // The output directory of compilation result.
  sourceMap: true, // [OPTIONAL] Generate sourceMap file
  sourceRoot: '', // [OPTIONAL] Source root path.
  mapRoot: './ts', // [OPTIONAL] SourceMap root directory
  basePath: './ts', // Typescript root directory
  removeComments: false, // [OPTIONAL] [true/false] Save comments on generated source.
  target: 'es3', // [es3/es5] Target ecmascript environment.
  module: 'amd', // [amd/commonjs] Target javascript module.
  useCaseSensitiveFileResolution: true, // [OPTIONAL] [true/false] To use case sensitive module search.
  locale: 'en', // [OPTIONAL] [en/ja-jp] Locale.
  noImplicitAny: false, // [OPTIONAL] [true/false] Whether allow implicit any or not.
  requirejsPath: 'js/libs/requirejs/require.js', // The path to the requirejs
  requirejsConfigPath: 'js/requirejs.config.js', // The path to the requirejs config file.
  urlRoot: './', // The url root path.
  updateAll: true // [OPTIONAL] [true/false] Whether record all typescript file mtime before server running or not.
  respond: true // [OPTIONAL] [true/false] Respond compilation result as requirejs main.
}));

Compilation

All typescript files are compiled if mtime is updated,
to get mtime value, we use fs.statSync

Options

outDir

The output directory of the compilation results.

sourceMap

[OPTIONAL] Generate sourceMap files.
values: true/false
default: false

sourceRoot

[OPTIONAL] The source root path for typescript.

mapRoot

[OPTIONAL] The source map root path.

basePath

The typescript root path.

removeComments

[OPTIONAL] Whether remove comments from generated source code or not.
values: true/false
default: true

target

[OPTIONAL] Target runtime for generated source code.
values: 'es3'/'es5'
default: 'es5'

module

[OPTIONAL] The module pattern for generated source code.
values: 'amd'/'commonjs'
default: 'amd'

useCaseSensitiveFileResolution

[OPTIONAL] Whether search referenced module by case sensitive.
value: true/false
default: true

locale

[OPTIONAL] The locale
value: 'en'/'ja-jp'
default: 'en'

noImplicitAny

[OPTIONAL] disallow implicit any type.
value: true/false default: false

requirejsPath

[OPTIONAL] Specify requirejs path for auto running.
This option affect only if respond option is true.

requirejsConfigPath

[OPTIONAL] Specify requirejs config file path.
This option affect only if respond option is true.

urlRoot

The root path of static files.

updateAll

[OPTIONAL] Collect mtime of the all modules, before accessed. values: true/false default: false

respond

[OPTIONAL] Respond compilation result as requirejs main file. values: true/false default: true

usePathname

[OPTIONAL] Use path name for decide compile target.
If this option is false, compile target is decided by 'path' query parameter. values: true/false default: false

Example(respond = true, usePathname = false)

Server

var connect = require('connect');
var app = connect();
app.use('typescript', tscMiddleware({
  basePath : '../ts/src',
  sourceMap: true,
  target: 'es3',
  module: 'amd',
  sourceMap: true,
  urlRoot: '../',
  outDir: '../js/output',
  requirejsPath: '../js/node_modules/requirejs/require.js',
  requirejsConfigPath: '../js/conf/requirejs.config.js',
  updateAll: true
})
.use(connect.static('../'))
.listen(8080);

HTML

<!doctype html>
<html>
<head>
  <script type="text/javascript" src="//localhost:8080/typescript?path=main/foo/bar/main.ts"></script>
</head>
<body>
</body>
</html>

Response

!function() {
  document.writeln('<script type="text/javascript" src="/js/conf/requirejs.config.js"><' + '/script>');
  document.writeln('<script type="text/javascript" src="/js/node_modules/requirejs/require.js" data-main="/js/output/foo/bar/main.js"><' + '/script>');
}();

Example(respond = false, usePathname = true)

Server

var connect = require('connect');
var app = connect();
app.use(tscMiddleware({
  basePath : '../ts/src',
  sourceMap: true,
  target: 'es3',
  module: 'amd',
  sourceMap: true,
  urlRoot: '../',
  outDir: '../js/output',
  requirejsPath: '../js/node_modules/requirejs/require.js',
  requirejsConfigPath: '../js/conf/requirejs.config.js',
  updateAll: true,
  respond: false,
  usePathname: true
})
.use(connect.static('../'))
.listen(8080);

HTML

<!doctype html>
<html>
<head>
  <!-Specify output file.-->
  <script type="text/javascript" src="//localhost:8080/js/output/main/foo/bar/main.js"></script>
</head>
<body>
</body>
</html>

typescript

class Main {}

export = Main;

Response

var Main = (function () {
    function Main() {
    }
    return Main;
})();

module.exports = Main;
//# sourceMappingURL=main.js.map