6.3.1
4.0.3
2.0.0
This is specific to typescript projects with source files importing protractor/globals
. Specifically, when importing protractor/globals
, because the NPM release includes the globals.ts
file instead of a corresponding definition file (globals.d.ts
) the typescript compiler will compute the consuming typescript project's common source root to the common path between the Protractor global.ts
dependency (likely node_modules/protractor
) and wherever the consuming project's sources are contained (for example, src/test/**/*.ts
). This leads the compiler to output the source files with all parent directories included.
Note that this is purely an issue with where the typescript compiler outputs the compiled files; the compilation happens fine, and protractor is consumed (as awesomely) as expected.
To better demonstrate the scenario I'm poorly describing, please see this example project.
I suspect resolving this here would be a combination of two things:
globals.ts
file is compiled; andglobals.ts
file from the NPM release package, leaving only the compiled javascript file and corresponding definition file.If this is sound, I'd be happy to submit a pull request to handle the first part of the solution. If the release process to NPM still follows the project's release document, I'd also be happy to update that with a step for removing the globals.ts
file, although that might be better doctored by someone who actually performs releases.
While I've thought this through and believe the Typescript compiler is behaving as expected, let me know if you disagree since I'm still getting my feet wet with Typescript.
(edit: updating format to reflect bug template)
@tmeneau Thank you for this issue: I really liked the github example... 👍 👍 👍
So this is a side affect when using outDir. For example if outDir
is set to output
, in addition to the transpiled files, output/node_modules/protractor/globals.js
would also be transpiled. I originally included the globals.ts file since (at the time) after some experimentation, you could not import a file types without having the TypeScript file.
To go through the proposals:
exampleTypescript
this appears to work. I am updating the .npmignore to not publish that file and upgrade Protractor to TypeScript 2. See: https://github.com/angular/protractor/pull/3485@cnishina glad the example helped! Thanks for the quick response, this looks great except for one thing I might be confused about: while your change removes the global.ts
file from the NPM package, won't not having a corresponding globals.d.ts
declaration make the protractor/globals
import invisible to the typescript compiler for consuming projects?
So I guess the first part of my proposal was not to remove the compiled globals.js
in favor of the globals.d.ts
declaration, but to have both so that NPM package will contain:
just without the globals.ts
source file.
I believe this can be achieved using tsc with the --declaration
flag when compiling the global.ts
file. For example, changing the tsc:globals gulp task like below should do the trick, although I noticed there are also tsc
and tsc:w
tasks in the package.json that might need to be updated as well provided that wouldn't modify non-global compilations adversely:
gulp.task('tsc:globals', function(done) {
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc', '--declaration', 'globals.ts'],
'ignore');
});
Let me know if I'm missing something, and thanks again for the quick fix! By the way, using Protractor with Typescript is a serious blast!
Yup... 👍 globals.d.ts
should still be there to get protractor/globals
import working. I updated the PR. Thanks!
Most helpful comment
@cnishina glad the example helped! Thanks for the quick response, this looks great except for one thing I might be confused about: while your change removes the
global.ts
file from the NPM package, won't not having a correspondingglobals.d.ts
declaration make theprotractor/globals
import invisible to the typescript compiler for consuming projects?So I guess the first part of my proposal was not to remove the compiled
globals.js
in favor of theglobals.d.ts
declaration, but to have both so that NPM package will contain:just without the
globals.ts
source file.I believe this can be achieved using tsc with the
--declaration
flag when compiling theglobal.ts
file. For example, changing the tsc:globals gulp task like below should do the trick, although I noticed there are alsotsc
andtsc:w
tasks in the package.json that might need to be updated as well provided that wouldn't modify non-global compilations adversely:Let me know if I'm missing something, and thanks again for the quick fix! By the way, using Protractor with Typescript is a serious blast!