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

Get ready to publish Alloy as an NPM repo #637

Merged
merged 33 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5548e15
CORE-52172 expose ES modules so Launch extension can consume npm repo
jonsnyder Oct 8, 2020
8cdcc34
CORE-52172 add tests and ignores, add more terser options
jonsnyder Oct 12, 2020
fdf619f
CORE-52172 add readme
jonsnyder Oct 14, 2020
ca0139e
Merge remote-tracking branch 'origin/master' into npmLibrary
jonsnyder Nov 2, 2020
f4f37ba
CORE-52172 add test files to pass lint test
jonsnyder Nov 2, 2020
6213606
CORE-52172 finish readme, setup files array, fix terser options
jonsnyder Nov 3, 2020
6cc1416
Merge remote-tracking branch 'origin/main' into npmLibrary
jonsnyder Nov 13, 2020
9b459e2
expose es6 and commonjs modules, address PR comments
jonsnyder Nov 13, 2020
c48cc80
Remove typescript from package.json
jonsnyder Nov 16, 2020
ca0892a
Fix event merge id issue
jonsnyder Nov 30, 2020
8e34421
Make the generated baseCode identical to pre-npm library version
jonsnyder Nov 30, 2020
41fcfda
Do not rollup es5 and es6 verions
jonsnyder Dec 1, 2020
821977d
update babel/cli version
jonsnyder Dec 8, 2020
ccbbef9
Add rimraf
jonsnyder Dec 8, 2020
922bb03
Use rimraf directly in prepublish script
jonsnyder Dec 8, 2020
a2a9893
Remove installation instructions from github README
jonsnyder Dec 16, 2020
dda91a0
CORE-52500 remove 'the' in Readme, remove jscc dependency
jonsnyder Dec 16, 2020
a46c2d4
Merge remote-tracking branch 'origin/main' into npmLibrary
jonsnyder Dec 16, 2020
3ce8902
Merge remote-tracking branch 'origin/main' into npmLibrary
jonsnyder Jan 5, 2021
f4c5646
expose a createInstance function rather than core and baseCode
jonsnyder Jan 5, 2021
d54c472
Add functional test for NPM library
jonsnyder Jan 15, 2021
0b5b65d
Merge remote-tracking branch 'origin/main' into npmLibrary
jonsnyder Jan 15, 2021
eb9e8f7
Remove wait for globalFunction in npmLibrary test
jonsnyder Jan 15, 2021
52e5fee
Rename createInstance in test
jonsnyder Jan 16, 2021
d18dc14
Merge remote-tracking branch 'origin/main' into npmLibrary
jonsnyder Jan 19, 2021
f5f7c57
Use NPM Library in prod for integration tests
jonsnyder Jan 19, 2021
a5e7a39
explicitly include index in imports to allow Launch packager to work
jonsnyder Jan 20, 2021
ff5b019
Revert "explicitly include index in imports to allow Launch packager …
jonsnyder Jan 21, 2021
b8eb968
rename build folders and files
jonsnyder Jan 22, 2021
f008c43
update package-lock.json
jonsnyder Jan 22, 2021
55d7cd3
Remove npmPackageProd until npm package is deployed
jonsnyder Jan 22, 2021
acf533f
Fix build to output the baseCode
jonsnyder Jan 23, 2021
345ba85
fix rollup for sandbox
jonsnyder Jan 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test:unit:coverage": "karma start --single-run --reporters spec,coverage",
"test:functional": "rollup -c --environment BUILD:prod && EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" testcafe chrome",
"test:functional:watch": "EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" BUILD=\"prod\" ./scripts/watchFunctionalTests.js",
"test:functional:ci:chrome": "EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" testcafe 'browserstack:chrome@87:Windows 10'",
"test:functional:ci:chrome": "EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" testcafe 'browserstack:chrome@87:OS X'",
"test:functional:ci:ie": "EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" testcafe 'browserstack:ie@11:Windows 10'",
"test:functional:cron:prod": "ALLOY_ENV=\"prod\" testcafe 'browserstack:chrome@87:OS X'",
"test:functional:api": "testcafe chrome:headless",
Expand Down
File renamed without changes.
244 changes: 124 additions & 120 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import createInstance from "./createInstance";
import createInstanceFunction from "./createInstanceFunction";
import { getApexDomain, injectStorage, cookieJar, isFunction } from "../utils";
import createLogController from "./createLogController";
import createLifecycle from "./createLifecycle";
Expand Down Expand Up @@ -41,140 +41,144 @@ import injectProcessWarningsAndErrors from "./edgeNetwork/injectProcessWarningsA
import validateNetworkResponseIsWellFormed from "./edgeNetwork/validateNetworkResponseIsWellFormed";
import isRetryableHttpStatusCode from "./network/isRetryableHttpStatusCode";

export default () => {
// eslint-disable-next-line no-underscore-dangle
const instanceNames = window.__alloyNS;
const createNamespacedStorage = injectStorage(window);

const createNamespacedStorage = injectStorage(window);
const { console, fetch, navigator, XMLHttpRequest } = window;

const { console, fetch, navigator, XMLHttpRequest } = window;
// set this up as a function so that monitors can be added at anytime
// eslint-disable-next-line no-underscore-dangle
const getMonitors = () => window.__alloyMonitors || [];

// set this up as a function so that monitors can be added at anytime
// eslint-disable-next-line no-underscore-dangle
const getMonitors = () => window.__alloyMonitors || [];
const coreConfigValidators = createCoreConfigs();
const apexDomain = getApexDomain(window, cookieJar);
const sendFetchRequest = isFunction(fetch)
? injectSendFetchRequest({ fetch })
: injectSendXhrRequest({ XMLHttpRequest });

const coreConfigValidators = createCoreConfigs();
const apexDomain = getApexDomain(window, cookieJar);
const sendFetchRequest = isFunction(fetch)
? injectSendFetchRequest({ fetch })
: injectSendXhrRequest({ XMLHttpRequest });

if (instanceNames) {
instanceNames.forEach(instanceName => {
const {
setDebugEnabled,
logger,
createComponentLogger
} = createLogController({
console,
locationSearch: window.location.search,
createLogger,
instanceName,
createNamespacedStorage,
getMonitors
});
const componentRegistry = createComponentRegistry();
const lifecycle = createLifecycle(componentRegistry);
export const createExecuteCommand = instanceName => {
const {
setDebugEnabled,
logger,
createComponentLogger
} = createLogController({
console,
locationSearch: window.location.search,
createLogger,
instanceName,
createNamespacedStorage,
getMonitors
});
const componentRegistry = createComponentRegistry();
const lifecycle = createLifecycle(componentRegistry);

const setDebugCommand = options => {
setDebugEnabled(options.enabled, { fromConfig: false });
};
const setDebugCommand = options => {
setDebugEnabled(options.enabled, { fromConfig: false });
};

const configureCommand = options => {
const config = buildAndValidateConfig({
options,
componentCreators,
coreConfigValidators,
createConfig,
logger,
setDebugEnabled
});
const cookieTransfer = createCookieTransfer({
cookieJar,
orgId: config.orgId,
apexDomain
});
const sendBeaconRequest = isFunction(navigator.sendBeacon)
? injectSendBeaconRequest({
// Without the bind(), the browser will complain about an
// illegal invocation.
sendBeacon: navigator.sendBeacon.bind(navigator),
sendFetchRequest,
logger
})
: sendFetchRequest;
const networkStrategy = injectNetworkStrategy({
const configureCommand = options => {
const config = buildAndValidateConfig({
options,
componentCreators,
coreConfigValidators,
createConfig,
logger,
setDebugEnabled
});
const cookieTransfer = createCookieTransfer({
cookieJar,
orgId: config.orgId,
apexDomain
});
const sendBeaconRequest = isFunction(navigator.sendBeacon)
? injectSendBeaconRequest({
// Without the bind(), the browser will complain about an
// illegal invocation.
sendBeacon: navigator.sendBeacon.bind(navigator),
sendFetchRequest,
sendBeaconRequest
});
const sendNetworkRequest = injectSendNetworkRequest({
logger,
networkStrategy,
isRetryableHttpStatusCode
});
const processWarningsAndErrors = injectProcessWarningsAndErrors({
logger
});
const sendEdgeNetworkRequest = injectSendEdgeNetworkRequest({
config,
lifecycle,
cookieTransfer,
sendNetworkRequest,
createResponse,
processWarningsAndErrors,
validateNetworkResponseIsWellFormed
});
})
: sendFetchRequest;
const networkStrategy = injectNetworkStrategy({
sendFetchRequest,
sendBeaconRequest
});
const sendNetworkRequest = injectSendNetworkRequest({
logger,
networkStrategy,
isRetryableHttpStatusCode
});
const processWarningsAndErrors = injectProcessWarningsAndErrors({
logger
});
const sendEdgeNetworkRequest = injectSendEdgeNetworkRequest({
config,
lifecycle,
cookieTransfer,
sendNetworkRequest,
createResponse,
processWarningsAndErrors,
validateNetworkResponseIsWellFormed
});

const generalConsentState = createConsentStateMachine();
const consent = createConsent({
generalConsentState,
logger
});
const eventManager = createEventManager({
const generalConsentState = createConsentStateMachine();
const consent = createConsent({
generalConsentState,
logger
});
const eventManager = createEventManager({
config,
logger,
lifecycle,
consent,
createEvent,
createDataCollectionRequestPayload,
sendEdgeNetworkRequest
});
return initializeComponents({
componentCreators,
lifecycle,
componentRegistry,
getImmediatelyAvailableTools(componentName) {
const componentLogger = createComponentLogger(componentName);
return {
config,
logger,
lifecycle,
consent,
createEvent,
createDataCollectionRequestPayload,
sendEdgeNetworkRequest
});
return initializeComponents({
componentCreators,
eventManager,
logger: componentLogger,
lifecycle,
componentRegistry,
getImmediatelyAvailableTools(componentName) {
const componentLogger = createComponentLogger(componentName);
return {
config,
consent,
eventManager,
logger: componentLogger,
lifecycle,
sendEdgeNetworkRequest,
handleError: injectHandleError({
errorPrefix: `[${instanceName}] [${componentName}]`,
logger: componentLogger
})
};
}
});
};
sendEdgeNetworkRequest,
handleError: injectHandleError({
errorPrefix: `[${instanceName}] [${componentName}]`,
logger: componentLogger
})
};
}
});
};

const handleError = injectHandleError({
errorPrefix: `[${instanceName}]`,
logger
});
const handleError = injectHandleError({
errorPrefix: `[${instanceName}]`,
logger
});

const executeCommand = injectExecuteCommand({
logger,
configureCommand,
setDebugCommand,
handleError,
validateCommandOptions
});
const executeCommand = injectExecuteCommand({
logger,
configureCommand,
setDebugCommand,
handleError,
validateCommandOptions
});
return { executeCommand, logger };
};

const instance = createInstance(executeCommand);
export default () => {
// eslint-disable-next-line no-underscore-dangle
const instanceNames = window.__alloyNS;

if (instanceNames) {
instanceNames.forEach(instanceName => {
const { executeCommand, logger } = createExecuteCommand(instanceName);
const instance = createInstanceFunction(executeCommand);

const queue = window[instanceName].q;
queue.push = instance;
Expand Down
17 changes: 7 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ governing permissions and limitations under the License.
// like the launch extension. Everything that is exported here can be used independently by other
// npm projects.

import baseCodeWithWindow from "./baseCode/index";
import { createExecuteCommand } from "./core";

export const baseCode = instanceNames => {
baseCodeWithWindow(window, instanceNames);
export default instanceName => {
const { executeCommand: instance, logger } = createExecuteCommand(
instanceName
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would make more sense to create the "log controller" here and pass it into createExecuteCommand rather than creating the log controller inside createExecuteCommand and exporting logger?

logger.logOnInstanceCreated({ instance });
return instance;
};

export { default as core } from "./core";

// createEventMergeId is used by the Launch extension to provide a synchronous way to create an id
export {
default as createEventMergeId
} from "./components/EventMerge/createEventMergeId";
2 changes: 1 addition & 1 deletion test/functional/helpers/createFixture/clientScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const remotePromisePolyfillPath =
"https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js";
const remoteVisitorLibraryUrl =
"https://github.com/Adobe-Marketing-Cloud/id-service/releases/latest/download/visitorapi.min.js";
const baseCodePath = path.join(__dirname, "../../../../dist/baseCode.min.js");
const baseCodePath = path.join(__dirname, "../../../../dist/baseCode.js");
const localAlloyLibraryPath = path.join(__dirname, "../../../../dist/alloy.js");
const remoteAlloyLibraryUrl =
"https://cdn1.adoberesources.net/alloy/latest/alloy.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import createInstance from "../../../../src/core/createInstance";
import createInstance from "../../../../src/core/createInstanceFunction";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to rename createInstance to createInstanceFunction here.

import flushPromiseChains from "../../helpers/flushPromiseChains";

describe("createInstance", () => {
Expand Down