Skip to content
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

chore(): Fix build in windows and test build/node in different OSes #2922

Merged
merged 9 commits into from
Sep 2, 2021
Prev Previous commit
Dont fail the build on typedoc failure
  • Loading branch information
jamesdaniels committed Sep 2, 2021
commit 031b61dae3414ad2b0d4ba3dffd218d1bed7f2cb
125 changes: 70 additions & 55 deletions tools/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function zoneWrapExports() {
});
const zoneWrapped = toBeExported.filter(([, , zoneWrap]) => zoneWrap);
const rawExport = toBeExported.filter(([, , zoneWrap]) => !zoneWrap);
await writeFile(`./src/${module}/${name}.ts`, `// DO NOT MODIFY, this file is autogenerated by tools/build.ts
await writeFile(join(process.cwd(), 'src', `${module}/${name}.ts`), `// DO NOT MODIFY, this file is autogenerated by tools/build.ts
${path.startsWith('firebase/') ? `export * from '${path}';\n` : ''}${
zoneWrapped.length > 0 ? `import { ɵzoneWrap } from '@angular/fire';
import {
Expand Down Expand Up @@ -109,13 +109,14 @@ ${zoneWrapped.map(([importName, exportName]) => `export const ${exportName} = ɵ
}

function webpackFirestoreProtos() {
// TODO fix on windows
return new Promise<void>((resolve, reject) => {
glob('./node_modules/@firebase/firestore/dist/src/protos/**/*.proto', {}, async (err, files) => {
if (err) { reject(err); }
const fileLoader = files.map(path =>
`require('file-loader?name=${path.replace('./node_modules/@firebase/firestore/dist/', '')}!${path.replace('./node_modules/', '../../')}');`
).join('\n');
await writeFile('./dist/packages-dist/firestore-protos.js', fileLoader);
await writeFile(dest('firestore-protos.js'), fileLoader);
resolve();
});
});
Expand All @@ -132,7 +133,7 @@ function proxyPolyfillCompat() {
};

return Promise.all(Object.keys(defaultObject).map(module =>
writeFile(`./src/${module}/base.ts`, `// DO NOT MODIFY, this file is autogenerated by tools/build.ts
writeFile(join(process.cwd(), 'src', `${module}/base.ts`), `// DO NOT MODIFY, this file is autogenerated by tools/build.ts
// Export a null object with the same keys as firebase/${module}, so Proxy can work with proxy-polyfill in Internet Explorer
export const proxyPolyfillCompat = {
${defaultObject[module].map(it => ` ${it}: null,`).join('\n')}
Expand Down Expand Up @@ -197,6 +198,7 @@ async function fixImportForLazyModules() {
const entries = Array.from(new Set(Object.values(packageJson).filter(v => typeof v === 'string' && v.endsWith('.js')))) as string[];
// TODO don't hardcode esm2015 here, perhaps we should scan all the entry directories
// e.g, if ng-packagr starts building other non-flattened entries we'll lose the dynamic import
// TODO fix in Windows
entries.push(`../${module.includes('/') ? '../' : ''}esm2015/${module}/public_api.js`);
await Promise.all(entries.map(async path => {
const source = (await readFile(dest(module, path))).toString();
Expand Down Expand Up @@ -233,59 +235,72 @@ function measureLibrary() {
}

async function buildDocs() {
// INVESTIGATE json to stdout rather than FS?
await Promise.all(MODULES.map(module => spawnPromise('npx', ['typedoc', `${module === 'core' ? './src' : `./src/${module}`}`, '--json', `./dist/typedocs/${module}.json`])));
const entries = await Promise.all(MODULES.map(async (module) => {
try {
// INVESTIGATE json to stdout rather than FS?
await Promise.all(
MODULES.map(module =>
spawnPromise('npx', ['typedoc',
`${module === 'core' ?
join(process.cwd(), 'src') :
join(process.cwd(), 'src', module)}`,
'--json',
join(process.cwd(), 'dist', 'typedocs', `${module}.json`)
])));
const entries = await Promise.all(MODULES.map(async (module) => {

const buffer = await readFile(join(process.cwd(), 'dist', 'typedocs', `${module}.json`));
const typedoc = JSON.parse(buffer.toString());
if (!typedoc.children) {
console.error('typedoc fail', module);
}
// TODO infer the entryPoint from the package.json
const entryPoint = typedoc.children.find((c: any) => c.name === '"public_api"');
const allChildren = [].concat(...typedoc.children.map(child =>
// TODO chop out the working directory and filename
child.children ?
child.children.map(c => {
return { ...c, path: dirname(child.originalName.split(process.cwd())[1]) };
}) :
[]
));
return (entryPoint.children || [])
.filter(c => c.name[0] !== 'ɵ' && c.name[0] !== '_' /* private */)
.map(child => ({ ...allChildren.find(c => child.target === c.id) }))
.reduce((acc, child) => ({ ...acc, [encodeURIComponent(child.name)]: child }), {});
}));
const root = await rootPackage;
const pipes = ['MonoTypeOperatorFunction', 'OperatorFunction', 'AuthPipe', 'UnaryFunction'];
const tocType = child => {
const decorators: string[] = child.decorators && child.decorators.map(d => d.name) || [];
if (decorators.includes('NgModule')) {
return 'NgModule';
} else if (child.kindString === 'Type alias') {
return 'Type alias';
} else if (child.kindString === 'Variable' && child.defaultValue && child.defaultValue.startsWith('new InjectionToken')) {
return 'InjectionToken';
} else if (child.type) {
return pipes.includes(child.type.name) ? 'Pipe' : child.type.name;
} else if (child.signatures && child.signatures[0] && child.signatures[0].type && pipes.includes(child.signatures[0].type.name)) {
return 'Pipe';
} else {
return child.kindString;
}
};
const tableOfContents = entries.reduce((acc, entry, index) =>
({
...acc, [MODULES[index]]: {
name: ENTRY_NAMES[index],
exports: Object.keys(entry).reduce((acc, key) => ({ ...acc, [key]: tocType(entry[key]) }), {})
}
}),
{}
);
const afdoc = entries.reduce((acc, entry, index) => ({ ...acc, [MODULES[index]]: entry }), { table_of_contents: tableOfContents });
return writeFile(`./api-${root.version}.json`, JSON.stringify(afdoc, null, 2));
const buffer = await readFile(join(process.cwd(), 'dist', 'typedocs', `${module}.json`));
const typedoc = JSON.parse(buffer.toString());
if (!typedoc.children) {
console.error('typedoc fail', module);
}
// TODO infer the entryPoint from the package.json
const entryPoint = typedoc.children.find((c: any) => c.name === '"public_api"');
const allChildren = [].concat(...typedoc.children.map(child =>
// TODO chop out the working directory and filename
child.children ?
child.children.map(c => {
return { ...c, path: dirname(child.originalName.split(process.cwd())[1]) };
}) :
[]
));
return (entryPoint.children || [])
.filter(c => c.name[0] !== 'ɵ' && c.name[0] !== '_' /* private */)
.map(child => ({ ...allChildren.find(c => child.target === c.id) }))
.reduce((acc, child) => ({ ...acc, [encodeURIComponent(child.name)]: child }), {});
}));
const root = await rootPackage;
const pipes = ['MonoTypeOperatorFunction', 'OperatorFunction', 'AuthPipe', 'UnaryFunction'];
const tocType = child => {
const decorators: string[] = child.decorators && child.decorators.map(d => d.name) || [];
if (decorators.includes('NgModule')) {
return 'NgModule';
} else if (child.kindString === 'Type alias') {
return 'Type alias';
} else if (child.kindString === 'Variable' && child.defaultValue && child.defaultValue.startsWith('new InjectionToken')) {
return 'InjectionToken';
} else if (child.type) {
return pipes.includes(child.type.name) ? 'Pipe' : child.type.name;
} else if (child.signatures && child.signatures[0] && child.signatures[0].type && pipes.includes(child.signatures[0].type.name)) {
return 'Pipe';
} else {
return child.kindString;
}
};
const tableOfContents = entries.reduce((acc, entry, index) =>
({
...acc, [MODULES[index]]: {
name: ENTRY_NAMES[index],
exports: Object.keys(entry).reduce((acc, key) => ({ ...acc, [key]: tocType(entry[key]) }), {})
}
}),
{}
);
const afdoc = entries.reduce((acc, entry, index) => ({ ...acc, [MODULES[index]]: entry }), { table_of_contents: tableOfContents });
return writeFile(join(process.cwd(), `api-${root.version}.json`), JSON.stringify(afdoc, null, 2));
} catch (e) {
console.warn(e);
return Promise.resolve();
}
}

Promise.all([
Expand Down