-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Build sytem: allow customization of some build options (such as global name) to NPM consumers #13685
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
Merged
Merged
Build sytem: allow customization of some build options (such as global name) to NPM consumers #13685
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1852d6b
Build system: translate exports (and not just imports) from .ts files
dgirardi 4e5baab
add global options
dgirardi 45707c5
contain use of 16010PREBID_GLOBAL16010 macro
dgirardi cd9b2ec
allow custom global / defineGlobal
dgirardi 85f1559
allow distUrlBase customization
dgirardi 7c33041
allow extensionless import
dgirardi 0a55f90
update README
dgirardi dec46a5
Merge branch 'master' into allow-global-def
dgirardi e6fbc68
fix eslint config
dgirardi e0e56f3
consistent quotes
dgirardi fcc85f3
remove useless comment
dgirardi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import path from 'path' | ||
import validate from 'schema-utils' | ||
|
||
const boModule = path.resolve(import.meta.dirname, '../dist/src/buildOptions.mjs') | ||
|
||
export function getBuildOptionsModule () { | ||
return boModule | ||
} | ||
|
||
const schema = { | ||
type: 'object', | ||
properties: { | ||
globalVarName: { | ||
type: 'string', | ||
description: 'Prebid global variable name. Default is "pbjs"', | ||
}, | ||
defineGlobal: { | ||
type: 'boolean', | ||
description: 'If false, do not set a global variable. Default is true.' | ||
}, | ||
distUrlBase: { | ||
type: 'string', | ||
description: 'Base URL to use for dynamically loaded modules (e.g. debugging-standalone.js)' | ||
} | ||
} | ||
} | ||
|
||
export function getBuildOptions (options = {}) { | ||
validate(schema, options, { | ||
name: 'Prebid build options', | ||
}) | ||
const overrides = {} | ||
if (options.globalVarName != null) { | ||
overrides.pbGlobal = options.globalVarName | ||
} | ||
['defineGlobal', 'distUrlBase'].forEach((option) => { | ||
if (options[option] != null) { | ||
overrides[option] = options[option] | ||
} | ||
}) | ||
return import(getBuildOptionsModule()) | ||
.then(({ default: defaultOptions }) => { | ||
return Object.assign( | ||
{}, | ||
defaultOptions, | ||
overrides | ||
) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getBuildOptions, getBuildOptionsModule } from './buildOptions.mjs' | ||
|
||
export default async function (source) { | ||
if (this.resourcePath !== getBuildOptionsModule()) { | ||
return source | ||
} | ||
return `export default ${JSON.stringify(await getBuildOptions(this.getOptions()), null, 2)};` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
// eslint-disable-next-line prebid/validate-imports | ||
import buildOptions from "../buildOptions.mjs"; // autogenerated during precompilation | ||
|
||
export function getGlobalVarName(): string { | ||
return buildOptions.pbGlobal; | ||
} | ||
|
||
export function shouldDefineGlobal(): boolean { | ||
return buildOptions.defineGlobal; | ||
} | ||
|
||
export function getDistUrlBase(): string { | ||
return buildOptions.distUrlBase; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this different than
Prebid.js/modules/medianetBidAdapter.js
Line 23 in 7f61966
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getGlobal
returns the global object (the one that has.requestBids()
etc);getGlobalVarName
returns the global name (e.g.'pbjs'
).