export default function() { // These testcases are specific to one uncommon behaviour in path module. Few // of the functions in path module, treat '' strings as current working // directory. This test makes sure that the behaviour is intact between commits. // See: https://github.com/nodejs/node/pull/2106 var pwd = process.cwd(); // join will internally ignore all the zero-length strings and it will return // '.' if the joined string is a zero-length string. assert.equal(path.posix.join(''), '.'); assert.equal(path.posix.join('', ''), '.'); assert.equal(path.join(pwd), pwd); assert.equal(path.join(pwd, ''), pwd); // normalize will return '.' if the input is a zero-length string assert.equal(path.posix.normalize(''), '.'); assert.equal(path.normalize(pwd), pwd); // Since '' is not a valid path in any of the common environments, return false assert.equal(path.posix.isAbsolute(''), false); // resolve, internally ignores all the zero-length strings and returns the // current working directory assert.equal(path.resolve(''), pwd); assert.equal(path.resolve('', ''), pwd); // relative, internally calls resolve. So, '' is actually the current directory assert.equal(path.relative('', pwd), ''); assert.equal(path.relative(pwd, ''), ''); assert.equal(path.relative(pwd, pwd), ''); };
private constructor( relativeFlatIndexPath: string, readonly entryPoint: string, readonly moduleName: string|null) { this.flatIndexPath = path.posix.join(path.posix.dirname(entryPoint), relativeFlatIndexPath) .replace(/\.js$/, '') + '.ts'; }
.map(match => { const relativePath = path.posix.relative(slashedDirname, match); return path.posix.dirname(match) === slashedDirname ? `./${relativePath}` : relativePath; })
return service.resolveFile(uri.file(path.join(testDir, 'index.html'))).then(source => { const targetParent = uri.file(path.dirname(source.resource.fsPath)); const target = targetParent.with({ path: path.posix.join(targetParent.path, path.posix.basename(source.resource.path)) }); return service.copyFile(source.resource, target, true).then(copied => { assert.equal(copied.size, source.size); }); });
return this._getBundles().then((bundles) => { let sharedDepsBundle = (this.shell) ? this.urlFromPath(this.shell) : this.sharedBundleUrl; let sharedDeps = bundles.get(sharedDepsBundle) || []; let promises = []; if (this.shell) { let shellFile = this.analyzer.getFile(this.shell); console.assert(shellFile != null); let newShellContent = this._addSharedImportsToShell(bundles); shellFile.contents = new Buffer(newShellContent); } for (let fragment of this.allFragments) { let fragmentUrl = this.urlFromPath(fragment); let addedImports = (fragment === this.shell && this.shell) ? [] : [path.relative(path.dirname(fragmentUrl), sharedDepsBundle)]; let excludes = (fragment === this.shell && this.shell) ? [] : sharedDeps.concat(sharedDepsBundle); promises.push(new Promise((resolve, reject) => { let vulcanize = new Vulcanize({ abspath: null, fsResolver: this.analyzer.resolver, addedImports: addedImports, stripExcludes: excludes, inlineScripts: true, inlineCss: true, inputUrl: fragmentUrl, }); vulcanize.process(null, (err, doc) => { if (err) { reject(err); } else { resolve({ url: fragment, contents: doc, }); } }); })); } // vulcanize the shared bundle if (!this.shell && sharedDeps && sharedDeps.length !== 0) { logger.info(`generating shared bundle`); promises.push(this._generateSharedBundle(sharedDeps)); } return Promise.all(promises).then((bundles) => { // convert {url,contents}[] into a Map let contentsMap = new Map(); for (let bundle of bundles) { contentsMap.set(bundle.url, bundle.contents); } return contentsMap; }); });
return service.resolveFile(uri.file(path.join(testDir, 'deep', 'conway.js'))).then(source => { const targetParent = uri.file(testDir); const target = targetParent.with({ path: path.posix.join(targetParent.path, path.posix.basename(source.resource.path)) }); return service.copyFile(source.resource, target, true).then(res => { // CONWAY.js => conway.js assert.equal(fs.existsSync(res.resource.fsPath), true); assert.ok(fs.readdirSync(testDir).some(f => f === 'conway.js')); }); });
/** * Checks if a path points to webcomponents-lite.js and will change it to * webcomponents-bundle.js if it does. * * @param filePath path to transform. */ private webcomponentsLiteToBundle(filePath: string) { const pathObject = path.posix.parse(filePath); if (pathObject.base === 'webcomponents-lite.js') { pathObject.base = 'webcomponents-bundle.js'; } return path.posix.format(pathObject); }
export function pathFromUrl( root: LocalFsPath, // TODO(usergenic): PackageRelativeUrl are not *necessarily* always just a // relative path from root. Maybe subclass as PackageRelativeUrlPath or // something if this function doesn't disappear after // https://github.com/Polymer/polymer-build/issues/324 is addressed. url: PackageRelativeUrl): LocalFsPath { return path.normalize(decodeURIComponent(path.posix.join( posixifyPath(root), path.posix.join('/', url)))) as LocalFsPath; }
toDepNameAndPath(relativePath: string): { depName: string; path: string; } { let depName = path.join(path.dirname(this._current.depName), relativePath); let depPath = path.join(path.dirname(this._current.path), relativePath); if (path.posix) { // (windows) for git cli // path.posix are exists after node v0.12 depName = path.posix.join(path.dirname(this._current.depName), relativePath); depPath = path.posix.join(path.dirname(this._current.path), relativePath); } return { depName: depName, path: depPath, }; }
it('should list lazy routes recursively', () => { writeSomeRoutes(); const {program, host, options} = createProgram(['src/main.ts', 'src/child.ts', 'src/child2.ts']); const routes = NgTools_InternalApi_NG_2.listLazyRoutes({ program, host, angularCompilerOptions: options, entryModule: 'src/main#MainModule', }); expect(routes).toEqual({ './child#ChildModule': path.posix.join(testSupport.basePath, 'src/child.ts'), './child2#ChildModule2': path.posix.join(testSupport.basePath, 'src/child2.ts'), }); });