Is it possible to use `addGlobalData` within the .eleventy configuration file? - node.js

In the documentation (https://www.11ty.dev/docs/data-global-custom/) for Eleventy it states that you can use the following as one option for adding custom global data:
// .eleventy.js
module.exports = function(eleventyConfig) {
eleventyConfig.addGlobalData("myFunctionPromise", () => {
return new Promise((resolve) => {
setTimeout(resolve, 100, "foo");
})
});
};
When attempting to use this within the .eleventy.js project configuration file it fails with:
> eleventyConfig.addGlobalData is not a function
However, custom collections can be defined on eleventyConfig using eleventyConfig.addCollection without any issues.
What is the issue here?

The addGlobalData configuration is coming soon in Eleventy v1.0.0 (written in the header next to the title of the page). This version has not been released yet.
If you want to use the canary version of Eleventy v1.0.0, you can install it with:
npm install #11ty/eleventy#canary
Keep in mind that this is a canary version that may have bugs or other issues. You can track progress towards 1.0 via the GitHub milestone. In the meantime, you can use global data files to add global data to your site.

Related

Hot to configure metro for UI Kitten build in EAS CI?

I am trying to use #ui-kitten/metro-config with the new EAS build flow from Expo.
Everything works well when I build an app for development and serve it through a development client. However, when I build a standalone version, the custom mapping I defined through my mapping.json does not get applied.
The documentation linked above says that one would have to run a CLI command before building in a CI environment: ui-kitten bootstrap #eva-design/eva ./path-to/mapping.json. But I can't figure out where to place this command so that it gets executed on EAS build servers at the right time.
Here is a reproducible example: https://github.com/acrdlph/expo-mcve/tree/ui-kitten - in development builds (which depend on a dev client) the h1 size is re-defined according to the mapping.json. In the preview and production profiles the h1 tag defaults back to its normal size.
Grateful for all pointers!
I had the exact same issue. There seems to be an bug in the metro-configuration and the .json mapping, or it might be expected behavior, I am not entirely sure. I fixed it by applying the custom mapping.json in both the ApplicationProvider as:
import { default as theme } from './theme.json';
import { default as mapping} from './mapping.json';
....
<ApplicationProvider {...eva} theme={{ ...eva.dark, ...theme }} customMapping={mapping}>
<HomeScreen />
</ApplicationProvider>
And the metro.config.js file as:
const path = require('path');
const MetroConfig = require('#ui-kitten/metro-config');
const {getDefaultConfig} = require('expo/metro-config');
const config = getDefaultConfig(__dirname);
const evaConfig = {
evaPackage: '#eva-design/eva',
customMappingPath: path.resolve(__dirname, 'mapping.json'),};
module.exports = MetroConfig.create(evaConfig,config);
I found some insight in this issue https://githubhot.com/repo/akveo/react-native-ui-kitten/issues/1568

Can't load Features.Diagnostics

I'm creating a web client for joining Teams meetings with the ACS Calling SDK.
I'm having trouble loading the diagnostics API. Microsoft provides this page:
https://learn.microsoft.com/en-us/azure/communication-services/concepts/voice-video-calling/call-diagnostics
You are supposed to get the diagnostics this way:
const callDiagnostics = call.api(Features.Diagnostics);
This does not work.
I am loading the Features like this:
import { Features } from '#azure/communication-calling'
A statement console.log(Features) shows only these four features:
DominantSpeakers: (...)
Recording: (...)
Transcription: (...)
Transfer: (...)
Where are the Diagnostics??
User Facing Diagnostics
For anyone, like me, looking now...
ATOW, using the latest version of #azure/communication-calling SDK, the documented solution, still doesn't work:
const callDiagnostics = call.api(Features.Diagnostics);
call.api is undefined.
TL;DR
However, once the call is instantiated, this allows you to subscribe to changes:
const call = callAgent.join(/** your settings **/);
const userFacingDiagnostics = call.feature(Features.UserFacingDiagnostics);
userFacingDiagnostics.media.on("diagnosticChanged", (diagnosticInfo) => {
console.log(diagnosticInfo);
});
userFacingDiagnostics.network.on("diagnosticChanged", (diagnosticInfo) => {
console.log(diagnosticInfo);
});
This isn't documented in the latest version, but is under this alpha version.
Whether this will continue to work is anyone's guess ¯\(ツ)/¯
Accessing Pre-Call APIs
Confusingly, this doesn't currently work using the specified version, despite the docs saying it will...
Features.PreCallDiagnostics is undefined.
This is actually what I was looking for, but I can get what I want by setting up a test call asking for the latest values, like this:
const call = callAgent.join(/** your settings **/);
const userFacingDiagnostics = call.feature(Features.UserFacingDiagnostics);
console.log(userFacingDiagnostics.media.getLatest())
console.log(userFacingDiagnostics.network.getLatest())
Hope this helps :)
Currently the User Facing Diagnostics API is only available in the Public Preview and npm beta packages right now. I confirmed this with a quick test comparing the 1.1.0 and beta packages.
Check the following link:
https://github.com/Azure-Samples/communication-services-web-calling-tutorial/
Features are imported from the #azure/communication-calling,
for example:
const {
Features
} = require('#azure/communication-calling');

Retrieve file contents during Gatsby build

I need to pull in the contents of a program source file for display in a page generated by Gatsby. I've got everything wired up to the point where I should be able to call
// my-fancy-template.tsx
import { readFileSync } from "fs";
// ...
const fileContents = readFileSync("./my/relative/file/path.cs");
However, on running either gatsby develop or gatsby build, I'm getting the following error
This dependency was not found:
⠀
* fs in ./src/templates/my-fancy-template.tsx
⠀
To install it, you can run: npm install --save fs
However, all the documentation would suggest that this module is native to Node unless it is being run on the browser. I'm not overly familiar with Node yet, but given that gatsby build also fails (this command does not even start a local server), I'd be a little surprised if this was the problem.
I even tried this from a new test site (gatsby new test) to the same effect.
I found this in the sidebar and gave that a shot, but it appears it just declared that fs was available; it didn't actually provide fs.
It then struck me that while Gatsby creates the pages at build-time, it may not render those pages until they're needed. This may be a faulty assessment, but it ultimately led to the solution I needed:
You'll need to add the file contents to a field on File (assuming you're using gatsby-source-filesystem) during exports.onCreateNode in gatsby-node.js. You can do this via the usual means:
if (node.internal.type === `File`) {
fs.readFile(node.absolutePath, undefined, (_err, buf) => {
createNodeField({ node, name: `contents`, value: buf.toString()});
});
}
You can then access this field in your query inside my-fancy-template.tsx:
{
allFile {
nodes {
fields { content }
}
}
}
From there, you're free to use fields.content inside each element of allFile.nodes. (This of course also applies to file query methods.)
Naturally, I'd be ecstatic if someone has a more elegant solution :-)

AWSXRay.captureAsyncFunc() from Lambda - am I missing something?

I'm trying to get a custom X-Ray segment reporting, but I'm not seeing anything in the trace. My code looks something like this:
var AWSXRay = require('aws-xray-sdk-core');
AWSXRay.captureAsyncFunc('callSoapService', subsegment => {
doSomethingAsync(params, err => {
if (err) {
subsegment.close(err);
} else {
doSomethingElse().then(result => {
console.info('all done, now close the segment');
subsegment.close();
}, subsegment.close);
}
});
});
Do I need to add it to the parent segment or something?
ugh. there seems to be a bug with AWSXRay.captureHTTPs() - if I remove that call captureAsyncFunc() starts working
For the AWS X-Ray Node SDK, automatic mode is build on the continuation-local-storage (cls) package which has known compatibility issues with promise libraries. This is why your 'then' seems to be losing context. However, most of these libraries have various CLS shims available to provide the compatibility necessary to work.
Which promise library are you using?
For bluebird, there's 'cls-bluebird' or for Q there's 'cls-q' that's available that will get it working.
They usually ask to pass in the CLS namespace, which is available from xray.getNamespace().
Hope this helps.

Visual Studio 2013 NodeJS Tools, TypeScript, Keep Comments

That's my setup. VS 2013, with the Node JS Tools, and Typescript. Adding a .ts file is handled without a hiccup. I am having some issues with the npm integration, but I've been able to work around them.
I've also added EdgeJS. It doesn't yet support TypeScript but I just write my EdgeJS calls with regular JS in my TS files. The problem is that EdgeJS allos you to write your CS functions a few different ways.
One way is like the following, where the entire body is enclosed in a comment block:
var hello = edge.func(function () {/*
async(input) => {
return ".NET welcomes " + input.ToString();
}
*/});
Unfortunately, the TS compiler, by default, removes these comments and I can't find a way in this project type to change that behavior.
Am I just out of luck (for now)?
To preserve comments for TypeScript, you'll need to start them on a new line. In the example you provided, the multi-line comment is not preserved as it starts on the end of a line with code.
Simply move the block comment start:
var edge = edge.func(() => {
/*
async(input) => {
}
*/
});

Resources