Skip to content

Commit d787b47

Browse files
backed out buffer changes (#2640)
1 parent 73a6890 commit d787b47

File tree

10 files changed

+1047
-11
lines changed

10 files changed

+1047
-11
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Backed out `Buffer` removal changes",
4+
"packageName": "@microsoft/teams-js",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
}
146146
},
147147
"dependencies": {
148+
"skeleton-buffer": "file:./skeleton-buffer",
148149
"uuid": "^9.0.1"
149150
}
150151
}

packages/teams-js/jest.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ module.exports = {
77
globals: {
88
PACKAGE_VERSION: packageVersion,
99
},
10-
setupFilesAfterEnv: ['./jest-setup.cjs'],
10+
//setupFilesAfterEnv: ['./jest-setup.cjs'],
1111
};

packages/teams-js/rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default [
4242
typescript(),
4343
json(),
4444
commonjs(),
45-
nodePolyfills({ exclude: ['node_modules/**'] }),
45+
nodePolyfills(),
4646
],
4747
treeshake: {
4848
moduleSideEffects: [

packages/teams-js/src/internal/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable @typescript-eslint/ban-types */
22
/* eslint-disable @typescript-eslint/no-unused-vars */
3+
import { Buffer } from 'buffer';
34
import * as uuid from 'uuid';
45

56
import { minAdaptiveCardVersion } from '../public/constants';
67
import { AdaptiveCardVersion, SdkError } from '../public/interfaces';
78
import * as pages from '../public/pages/pages';
8-
import { base64ToString } from './uint8array-extras/uint8array-extras';
99

1010
/**
1111
* @internal
@@ -348,14 +348,14 @@ export function base64ToBlob(mimeType: string, base64String: string): Promise<Bl
348348
* constructor expects binary data.
349349
*/
350350
if (mimeType.startsWith('image/')) {
351-
const byteCharacters = base64ToString(base64String);
351+
const byteCharacters = atob(base64String);
352352
const byteArray = new Uint8Array(byteCharacters.length);
353353
for (let i = 0; i < byteCharacters.length; i++) {
354354
byteArray[i] = byteCharacters.charCodeAt(i);
355355
}
356356
resolve(new Blob([byteArray], { type: mimeType }));
357357
}
358-
const byteCharacters = base64ToString(base64String);
358+
const byteCharacters = Buffer.from(base64String, 'base64').toString();
359359
resolve(new Blob([byteCharacters], { type: mimeType }));
360360
});
361361
}

packages/teams-js/webpack.config.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ module.exports = {
3434
devtool: 'source-map',
3535
resolve: {
3636
extensions: ['.tsx', '.ts', '.js'],
37+
fallback: {
38+
buffer: require.resolve('skeleton-buffer/'),
39+
},
3740
},
3841
module: {
3942
rules: [
@@ -72,6 +75,10 @@ module.exports = {
7275
// https://www.npmjs.com/package/webpack-subresource-integrity
7376
new SubresourceIntegrityPlugin({ enabled: true }),
7477

78+
new ProvidePlugin({
79+
Buffer: ['skeleton-buffer', 'Buffer'],
80+
}),
81+
7582
// Webpackmanifest produces the json file containing asset(JS file) and its corresponding hash values(Example: https://github.com/waysact/webpack-subresource-integrity/blob/main/examples/webpack-assets-manifest/webpack.config.js)
7683
new WebpackAssetsManifest({
7784
integrity: true,

pnpm-lock.yaml

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

skeleton-buffer/index.d.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
export class Buffer extends Uint8Array {
2+
length: number;
3+
write(string: string, offset?: number, length?: number, encoding?: string): number;
4+
toString(encoding?: string, start?: number, end?: number): string;
5+
slice(start?: number, end?: number): Buffer;
6+
7+
/**
8+
* Allocates a new buffer containing the given {str}.
9+
*
10+
* @param str String to store in buffer.
11+
* @param encoding encoding to use, optional. Default is 'utf8'
12+
*/
13+
constructor(str: string, encoding?: string);
14+
/**
15+
* Allocates a new buffer of {size} octets.
16+
*
17+
* @param size count of octets to allocate.
18+
*/
19+
constructor(size: number);
20+
/**
21+
* Allocates a new buffer containing the given {array} of octets.
22+
*
23+
* @param array The octets to store.
24+
*/
25+
constructor(array: Uint8Array);
26+
/**
27+
* Produces a Buffer backed by the same allocated memory as
28+
* the given {ArrayBuffer}.
29+
*
30+
*
31+
* @param arrayBuffer The ArrayBuffer with which to share memory.
32+
*/
33+
constructor(arrayBuffer: ArrayBuffer);
34+
/**
35+
* Allocates a new buffer containing the given {array} of octets.
36+
*
37+
* @param array The octets to store.
38+
*/
39+
constructor(array: any[]);
40+
/**
41+
* Copies the passed {buffer} data onto a new {Buffer} instance.
42+
*
43+
* @param buffer The buffer to copy.
44+
*/
45+
constructor(buffer: Buffer);
46+
prototype: Buffer;
47+
/**
48+
* When passed a reference to the .buffer property of a TypedArray instance,
49+
* the newly created Buffer will share the same allocated memory as the TypedArray.
50+
* The optional {byteOffset} and {length} arguments specify a memory range
51+
* within the {arrayBuffer} that will be shared by the Buffer.
52+
*
53+
* @param arrayBuffer The .buffer property of a TypedArray or a new ArrayBuffer()
54+
* @param byteOffset
55+
* @param length
56+
*/
57+
static from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
58+
/**
59+
* Creates a new Buffer containing the given JavaScript string {str}.
60+
* If provided, the {encoding} parameter identifies the character encoding.
61+
* If not provided, {encoding} defaults to 'utf8'.
62+
*
63+
* @param str
64+
*/
65+
static from(str: string, encoding?: string): Buffer;
66+
/**
67+
* Returns true if {obj} is a Buffer
68+
*
69+
* @param obj object to test.
70+
*/
71+
static isBuffer(obj: any): obj is Buffer;
72+
/**
73+
* Returns true if {encoding} is a valid encoding argument.
74+
* Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
75+
*
76+
* @param encoding string to test.
77+
*/
78+
static isEncoding(encoding: string): boolean;
79+
/**
80+
* Gives the actual byte length of a string. encoding defaults to 'utf8'.
81+
* This is not the same as String.prototype.length since that returns the number of characters in a string.
82+
*
83+
* @param string string to test.
84+
* @param encoding encoding used to evaluate (defaults to 'utf8')
85+
*/
86+
static byteLength(string: string, encoding?: string): number;
87+
/**
88+
* Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents
89+
* of the newly created Buffer are unknown and may contain sensitive data.
90+
*
91+
* @param size count of octets to allocate
92+
*/
93+
static allocUnsafe(size: number): Buffer;
94+
}

0 commit comments

Comments
 (0)