Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error loading file from typescript package in bin folder due to IIS restriction (404s) #3408

Closed
wforney opened this issue Jun 7, 2015 · 8 comments
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@wforney
Copy link

wforney commented Jun 7, 2015

This issue came to light while trying to use this plugin for SystemJS... I filed an issue there and they suggested I also make one over here.

frankwallis/plugin-typescript#22 (comment)

The bin folder is blocked in IIS out of box so when installing your typescript plugin I got 404s when it attempted to download the typescript.js file from the bin folder of the typescript package... I'm not sure who publishes that or if you can work around it but it is a blocker for using this on IIS. Whoever maintains the typescript package you use should add a web.config allowing browsing of the bin folder or rename the bin folder something else that isn't blocked (preferred).

web.config contents to fix it below:

<configuration>
  <system.webServer>
   <security>
     <requestFiltering>
        <hiddenSegments applyToWebDAV="false">
           <remove segment="Bin" />
        </hiddenSegments>
     </requestFiltering>
   </security>
  </system.webServer>
</configuration>
@mhegazy
Copy link
Contributor

mhegazy commented Jun 8, 2015

One option is to rename bin to dist; but this is undesirable as bin is part of the npm conventions, and we have had that since TypeScript was first released, and we do not know who would be broken by this.

I will check with IIS/ASP.net folks to see if there are other workarounds.

@guybedford
Copy link
Contributor

@wforney are you saying here that a file web.config located in the base-level of the TypeScript folder with those contents would make this work in IIS?

@vladima
Copy link
Contributor

vladima commented Jul 22, 2015

yes, removing bin from the set of hidden segments will make it work however ASP.NET guys have not recommended to use this approach as it might result in a security hole (i.e. if some sensitive data is stored somewhere in folder named bin )

@vladima
Copy link
Contributor

vladima commented Jul 23, 2015

Here is what we can do with TypeScript npm package to unblock this scenario

  • rename bin to dist and change main to be dist/typescript.js
  • add a postinstall script to package.json that will create bin folder and fill it with links to files in dist.
var fs = require('fs');
var path = require('path');

var currentDirectory = process.cwd();
var distFolder = path.join(currentDirectory, "dist");
var files = fs.readdirSync(distFolder);

var binFolder = path.join(currentDirectory, "bin");
if (!fs.existsSync(binFolder)) {
    fs.mkdirSync(binFolder);
}

files.forEach(function(f) {
    var sourcePath = path.join(distFolder, f);
    var targetPath = path.join(binFolder, f);
    fs.linkSync(sourcePath, targetPath); // creating symlinks on Windows requires elevated permissions, in our case hardlinks will also work
});

This way we can be both backwards compatible in scenarios when somebody references typescript.js by relative path that has bin in it, use standard npm/jspm machinery to locate modules and don't bloat the size of the package.

@mhegazy does this solution work for you?

@mhegazy
Copy link
Contributor

mhegazy commented Jul 24, 2015

fine by me. @billti any concerns/ideas?

@mhegazy
Copy link
Contributor

mhegazy commented Jul 24, 2015

do we have to change main in package.json? i thought we can configure JSPM to find the right file without updating package.json?

@vladima
Copy link
Contributor

vladima commented Jul 24, 2015

@mhegazy if using overrides to specify different entry point does not put restrictions on some jspm scenarios we can do the other way around, keep everything in bin and create dist folder with links as a postinstall step. @guybedford can you please clarify if this solution is ok from the jspm perspective?

@billti
Copy link
Member

billti commented Jul 24, 2015

A canonical pattern for NPM modules is to have the command line in './bin' (i.e. the file we have at https://github.com/Microsoft/TypeScript/blob/master/bin/tsc ), and have the remainder of the content in a './lib' folder. We could leave the current files referenced by 'bin' entries in packageon.json there (i.e. tsc and tsserver) and move the other files to a lib folder, and the only package.json updates needed would be to point the main property to ./lib/typescript.js.

I'm not a fan of running post install scripts to create folders or putting files for orthogonal technologies (i.e. ASP.NET) in our NPM package. How big do we expect the impact of the move will be without doing these?

@vladima vladima added Fixed A PR has been merged for this issue Breaking Change Would introduce errors in existing code labels Jul 30, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

6 participants