Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function runBuildLambda(inputPath) {
const inputFiles = await glob('**', inputPath);
const nowJsonRef = inputFiles['now.json'];
expect(nowJsonRef).toBeDefined();
const nowJson = require(nowJsonRef.fsPath);
expect(nowJson.builds.length).toBe(1);
const build = nowJson.builds[0];
expect(build.src.includes('*')).toBeFalsy();
const entrypoint = build.src.replace(/^\//, ''); // strip leftmost slash
expect(inputFiles[entrypoint]).toBeDefined();
inputFiles[entrypoint].digest =
'this-is-a-fake-digest-for-non-default-analyze';
const wrapper = require(build.use);
const analyzeResult = runAnalyze(wrapper, {
files: inputFiles,
entrypoint,
config: build.config
});
async function runBuildLambda(inputPath) {
const inputFiles = await glob('**', inputPath)
const nowJsonRef = inputFiles['now.json']
const nowJson = require(nowJsonRef.fsPath)
const build = nowJson.builds[0]
const entrypoint = build.src.replace(/^\//, '') // Strip leftmost slash
inputFiles[entrypoint].digest = 'this-is-a-fake-digest-for-non-default-analyze'
const wrapper = require(build.use)
const analyzeResult = runAnalyze(wrapper, {
files: inputFiles,
entrypoint,
config: build.config
})
export async function createApiData({ props, state }) {
const { contents } = props;
const sandboxId = state.get('editor.currentId');
const sandbox = state.get(`editor.sandboxes.${sandboxId}`);
const template = getTemplate(sandbox.template);
let apiData = {
files: [],
};
let packageJSON = {};
let nowJSON = {};
const projectPackage = contents.files['package.json'];
const nowFile = contents.files['now.json'];
if (projectPackage) {
const data = await projectPackage.async('text'); // eslint-disable-line no-await-in-loop
const parsed = JSON.parse(data);
packageJSON = parsed;
}
if (nowFile) {
const data = await nowFile.async('text'); // eslint-disable-line no-await-in-loop
const parsed = JSON.parse(data);
nowJSON = parsed;
} else if (packageJSON.now) {
// Also support package.json if imported like that
nowJSON = packageJSON.now;
async function getApiData(contents: any, sandbox: Sandbox) {
const template = getTemplate(sandbox.template);
let apiData: Partial = {
files: [],
};
let packageJSON: any = {};
let nowJSON: any = {};
const projectPackage = contents.files['package.json'];
const nowFile = contents.files['now.json'];
if (projectPackage) {
const data = await projectPackage.async('text'); // eslint-disable-line no-await-in-loop
const parsed = JSON.parse(data);
packageJSON = parsed;
}
if (nowFile) {
const data = await nowFile.async('text'); // eslint-disable-line no-await-in-loop
const parsed = JSON.parse(data);
nowJSON = parsed;
} else if (packageJSON.now) {
// Also support package.json if imported like that
nowJSON = packageJSON.now;
build.config = build.config || {};
const { config } = build;
if (buildUtilsUrl === '@canary') {
config.useBuildUtils = config.useBuildUtils || '@now/build-utils';
config.useBuildUtils = `${config.useBuildUtils}@canary`;
} else {
config.useBuildUtils = `https://${buildUtilsUrl}`;
}
}
if (buildDelegate) {
buildDelegate(build);
}
}
bodies['now.json'] = Buffer.from(JSON.stringify(nowJson));
delete bodies['probe.js'];
const { deploymentId, deploymentUrl } = await nowDeploy(bodies, randomness);
console.log('deploymentUrl', `https://${deploymentUrl}`);
for (const probe of nowJson.probes || []) {
console.log('testing', JSON.stringify(probe));
if (probe.delay) {
await new Promise(resolve => setTimeout(resolve, probe.delay));
continue;
}
const probeUrl = `https://${deploymentUrl}${probe.path}`;
const fetchOpts = {
...probe.fetchOptions,
method: probe.method,
headers: { ...probe.headers },
};
}, {});
const randomness = Math.floor(Math.random() * 0x7fffffff)
.toString(16)
.repeat(6)
.slice(0, RANDOMNESS_PLACEHOLDER_STRING.length);
for (const file of Object.keys(bodies)) {
bodies[file] = bufferReplace(
bodies[file],
RANDOMNESS_PLACEHOLDER_STRING,
randomness
);
}
const nowJson = JSON.parse(bodies['now.json']);
for (const build of nowJson.builds) {
if (builderUrl) {
if (builderUrl === '@canary') {
build.use = `${build.use}@canary`;
} else {
build.use = `https://${builderUrl}`;
}
}
if (buildUtilsUrl) {
build.config = build.config || {};
const { config } = build;
if (buildUtilsUrl === '@canary') {
config.useBuildUtils = config.useBuildUtils || '@now/build-utils';
config.useBuildUtils = `${config.useBuildUtils}@canary`;
} else {
config.useBuildUtils = `https://${buildUtilsUrl}`;