build: make sure license information is preserved (#11971)

This commit is contained in:
Alex Rudenko 2024-02-22 13:42:59 +01:00 committed by GitHub
parent 753a954456
commit 873d6db020
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 76 additions and 36 deletions

View File

@ -4,12 +4,15 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import {mkdir, readFile, readdir, writeFile} from 'fs/promises'; import {mkdir, readFile, readdir, writeFile} from 'fs/promises';
import {join} from 'path/posix'; import Module from 'node:module';
import {join, dirname} from 'path/posix';
import esbuild from 'esbuild'; import esbuild from 'esbuild';
import {execa} from 'execa'; import {execa} from 'execa';
import {task} from 'hereby'; import {task} from 'hereby';
const require = Module.createRequire(import.meta.url);
export const generateVersionTask = task({ export const generateVersionTask = task({
name: 'generate:version', name: 'generate:version',
run: async () => { run: async () => {
@ -108,8 +111,35 @@ export const buildTask = task({
format, format,
target: 'node16', target: 'node16',
minify: true, minify: true,
legalComments: 'inline',
}) })
); );
let license = '';
switch (name) {
case 'rxjs':
license = await readFile(
`${dirname(require.resolve('rxjs'))}/../../LICENSE.txt`,
'utf-8'
);
break;
case 'mitt':
license = await readFile(
`${dirname(require.resolve('mitt'))}/../LICENSE`,
'utf-8'
);
break;
default:
throw new Error(`Add license handling for ${path}`);
}
const content = await readFile(path, 'utf-8');
await writeFile(
path,
`/**
${license}
*/
${content}`,
'utf-8'
);
} }
} }
await Promise.all(builders); await Promise.all(builders);

View File

@ -77,7 +77,8 @@
"files": [ "files": [
"{src,third_party}/**", "{src,third_party}/**",
"../../versions.js", "../../versions.js",
"!src/generated" "!src/generated",
"Herebyfile.mjs"
], ],
"output": [ "output": [
"lib/{cjs,esm}/**" "lib/{cjs,esm}/**"

View File

@ -9,7 +9,6 @@ import type {ChildProcess} from 'child_process';
import type {Protocol} from 'devtools-protocol'; import type {Protocol} from 'devtools-protocol';
import { import {
filterAsync,
firstValueFrom, firstValueFrom,
from, from,
merge, merge,
@ -17,7 +16,12 @@ import {
} from '../../third_party/rxjs/rxjs.js'; } from '../../third_party/rxjs/rxjs.js';
import type {ProtocolType} from '../common/ConnectOptions.js'; import type {ProtocolType} from '../common/ConnectOptions.js';
import {EventEmitter, type EventType} from '../common/EventEmitter.js'; import {EventEmitter, type EventType} from '../common/EventEmitter.js';
import {debugError, fromEmitterEvent, timeout} from '../common/util.js'; import {
debugError,
fromEmitterEvent,
filterAsync,
timeout,
} from '../common/util.js';
import {asyncDisposeSymbol, disposeSymbol} from '../util/disposable.js'; import {asyncDisposeSymbol, disposeSymbol} from '../util/disposable.js';
import type {BrowserContext} from './BrowserContext.js'; import type {BrowserContext} from './BrowserContext.js';

View File

@ -5,14 +5,18 @@
*/ */
import { import {
filterAsync,
firstValueFrom, firstValueFrom,
from, from,
merge, merge,
raceWith, raceWith,
} from '../../third_party/rxjs/rxjs.js'; } from '../../third_party/rxjs/rxjs.js';
import {EventEmitter, type EventType} from '../common/EventEmitter.js'; import {EventEmitter, type EventType} from '../common/EventEmitter.js';
import {debugError, fromEmitterEvent, timeout} from '../common/util.js'; import {
debugError,
fromEmitterEvent,
filterAsync,
timeout,
} from '../common/util.js';
import {asyncDisposeSymbol, disposeSymbol} from '../util/disposable.js'; import {asyncDisposeSymbol, disposeSymbol} from '../util/disposable.js';
import type {Browser, Permission, WaitForTargetOptions} from './Browser.js'; import type {Browser, Permission, WaitForTargetOptions} from './Browser.js';

View File

@ -10,7 +10,6 @@ import {
concat, concat,
EMPTY, EMPTY,
filter, filter,
filterAsync,
first, first,
firstValueFrom, firstValueFrom,
from, from,
@ -63,6 +62,7 @@ import type {
import { import {
debugError, debugError,
fromEmitterEvent, fromEmitterEvent,
filterAsync,
importFSPromises, importFSPromises,
isString, isString,
NETWORK_IDLE_TIME, NETWORK_IDLE_TIME,

View File

@ -6,7 +6,16 @@
import type FS from 'fs/promises'; import type FS from 'fs/promises';
import {map, NEVER, Observable, timer} from '../../third_party/rxjs/rxjs.js'; import type {OperatorFunction} from '../../third_party/rxjs/rxjs.js';
import {
filter,
from,
map,
mergeMap,
NEVER,
Observable,
timer,
} from '../../third_party/rxjs/rxjs.js';
import type {CDPSession} from '../api/CDPSession.js'; import type {CDPSession} from '../api/CDPSession.js';
import {assert} from '../util/assert.js'; import {assert} from '../util/assert.js';
@ -453,3 +462,21 @@ export function fromEmitterEvent<
}; };
}); });
} }
/**
* @internal
*/
export function filterAsync<T>(
predicate: (value: T) => boolean | PromiseLike<boolean>
): OperatorFunction<T, T> {
return mergeMap<T, Observable<T>>((value): Observable<T> => {
return from(Promise.resolve(predicate(value))).pipe(
filter(isMatch => {
return isMatch;
}),
map(() => {
return value;
})
);
});
}

View File

@ -1,8 +1,3 @@
/** // esline-disable rulesdir/check-license
* @license
* Copyright 2022 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
export * from 'mitt'; export * from 'mitt';
export {default as default} from 'mitt'; export {default as default} from 'mitt';

View File

@ -1,8 +1,4 @@
/** // esline-disable rulesdir/check-license
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
export { export {
bufferCount, bufferCount,
catchError, catchError,
@ -48,20 +44,3 @@ export {
} from 'rxjs'; } from 'rxjs';
export type * from 'rxjs'; export type * from 'rxjs';
import {filter, from, map, mergeMap, type Observable} from 'rxjs';
export function filterAsync<T>(
predicate: (value: T) => boolean | PromiseLike<boolean>
) {
return mergeMap<T, Observable<T>>(value => {
return from(Promise.resolve(predicate(value))).pipe(
filter(isMatch => {
return isMatch;
}),
map(() => {
return value;
})
);
});
}