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
*/
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 {execa} from 'execa';
import {task} from 'hereby';
const require = Module.createRequire(import.meta.url);
export const generateVersionTask = task({
name: 'generate:version',
run: async () => {
@ -108,8 +111,35 @@ export const buildTask = task({
format,
target: 'node16',
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);

View File

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

View File

@ -9,7 +9,6 @@ import type {ChildProcess} from 'child_process';
import type {Protocol} from 'devtools-protocol';
import {
filterAsync,
firstValueFrom,
from,
merge,
@ -17,7 +16,12 @@ import {
} from '../../third_party/rxjs/rxjs.js';
import type {ProtocolType} from '../common/ConnectOptions.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 type {BrowserContext} from './BrowserContext.js';

View File

@ -5,14 +5,18 @@
*/
import {
filterAsync,
firstValueFrom,
from,
merge,
raceWith,
} from '../../third_party/rxjs/rxjs.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 type {Browser, Permission, WaitForTargetOptions} from './Browser.js';

View File

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

View File

@ -6,7 +6,16 @@
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 {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 @@
/**
* @license
* Copyright 2022 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
// esline-disable rulesdir/check-license
export * from 'mitt';
export {default as default} from 'mitt';

View File

@ -1,8 +1,4 @@
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
// esline-disable rulesdir/check-license
export {
bufferCount,
catchError,
@ -48,20 +44,3 @@ export {
} 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;
})
);
});
}