Skip to content

Commit 888e112

Browse files
authored
Fix ESM build path (#78)
* style(prettier): fix broken prettier looking for @grafana/toolkit * fix(build): remove src/ from dist esm paths and prevent @emotion/css in dist/esm dir * fix(build): prevent import react; import @grafana/ui; in dist esm entrypoint * fix(circular-deps): prevent circular dependencies in components * refactor(entrypoint): prefer named exports of usage of * * docs(changelog): introduce entry for 0.3.3
1 parent 0202814 commit 888e112

10 files changed

+53
-40
lines changed

.prettierrc.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module.exports = {
2-
...require('@grafana/toolkit/src/config/prettier.plugin.config.json'),
2+
trailingComma: 'es5',
3+
singleQuote: true,
4+
printWidth: 120,
35
};

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## v0.3.3
6+
7+
- Fix: broken ESM imports due to `src` in ESM build output path
8+
- Fix: circular dependencies in components
9+
- Fix: ESM builds importing entire react, grafana/ui, grafana/data, and grafana/experimental
10+
- Refactor: prefer named exports over asterisk in barrel files
511

612
## v0.3.2
713

rollup.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default [
1313
plugins: [
1414
externals({
1515
deps: true,
16-
include: ['react', '@grafana/data', '@grafana/ui', '@grafana/runtime', 'lodash'],
16+
include: ['react', '@emotion/css', '@grafana/data', '@grafana/ui', '@grafana/runtime', 'lodash'],
1717
packagePath,
1818
}),
1919
resolve(),
@@ -30,6 +30,7 @@ export default [
3030
sourcemap: true,
3131
dir: path.dirname(pkg.module),
3232
preserveModules: true,
33+
preserveModulesRoot: './src',
3334
},
3435
],
3536
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { css } from '@emotion/css';
2+
3+
export const assumeRoleInstructionsStyle = css({
4+
maxWidth: '715px',
5+
});

src/components/ConnectionConfig.tsx

+4-26
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,24 @@
11
import React, { FC, useEffect, useMemo, useState } from 'react';
22
import { Input, Select, InlineField, ButtonGroup, ToolbarButton, FieldSet, Collapse } from '@grafana/ui';
33
import {
4-
DataSourcePluginOptionsEditorProps,
54
onUpdateDatasourceJsonDataOptionSelect,
65
onUpdateDatasourceResetOption,
76
onUpdateDatasourceJsonDataOption,
87
onUpdateDatasourceSecureJsonDataOption,
98
} from '@grafana/data';
109
import { config } from '@grafana/runtime';
1110
import { standardRegions } from '../regions';
12-
import { AwsAuthDataSourceJsonData, AwsAuthDataSourceSecureJsonData, AwsAuthType } from '../types';
11+
import { AwsAuthType, ConnectionConfigProps } from '../types';
1312
import { awsAuthProviderOptions } from '../providers';
14-
import { css } from '@emotion/css';
1513
import { NewConnectionConfig } from './NewConnectionConfig';
14+
import { assumeRoleInstructionsStyle } from './ConnectionConfig.styles';
1615

1716
export const DEFAULT_LABEL_WIDTH = 28;
1817
const DS_TYPES_THAT_SUPPORT_TEMP_CREDS = ['cloudwatch', 'grafana-athena-datasource'];
1918
const toOption = (value: string) => ({ value, label: value });
2019
const isAwsAuthType = (value: any): value is AwsAuthType => {
2120
return typeof value === 'string' && awsAuthProviderOptions.some((opt) => opt.value === value);
2221
};
23-
export interface ConnectionConfigProps<
24-
J extends AwsAuthDataSourceJsonData = AwsAuthDataSourceJsonData,
25-
S = AwsAuthDataSourceSecureJsonData
26-
> extends DataSourcePluginOptionsEditorProps<J, S> {
27-
standardRegions?: string[];
28-
loadRegions?: () => Promise<string[]>;
29-
defaultEndpoint?: string;
30-
skipHeader?: boolean;
31-
skipEndpoint?: boolean;
32-
children?: React.ReactNode;
33-
labelWidth?: number;
34-
inExperimentalAuthComponent?: boolean;
35-
externalId?: string;
36-
newFormStylingEnabled?: boolean;
37-
}
3822

3923
export const ConnectionConfig: FC<ConnectionConfigProps> = (props: ConnectionConfigProps) => {
4024
const [isARNInstructionsOpen, setIsARNInstructionsOpen] = useState(false);
@@ -184,9 +168,8 @@ export const ConnectionConfig: FC<ConnectionConfigProps> = (props: ConnectionCon
184168
<ol>
185169
<li>
186170
<p>
187-
1. Create a new IAM role in the AWS console,
188-
and select <code>AWS account</code> as the Trusted entity,
189-
and select <code>Another AWS account</code> as the account.
171+
1. Create a new IAM role in the AWS console, and select <code>AWS account</code> as the Trusted
172+
entity, and select <code>Another AWS account</code> as the account.
190173
</p>
191174
</li>
192175
<li>
@@ -302,8 +285,3 @@ export const ConnectionConfig: FC<ConnectionConfigProps> = (props: ConnectionCon
302285
</>
303286
);
304287
};
305-
306-
export const assumeRoleInstructionsStyle = css({
307-
maxWidth: '715px',
308-
})
309-

src/components/NewConnectionConfig.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {
77
onUpdateDatasourceSecureJsonDataOption,
88
SelectableValue,
99
} from '@grafana/data';
10-
import { AwsAuthType } from '../types';
10+
import { AwsAuthType, ConnectionConfigProps } from '../types';
1111
import { awsAuthProviderOptions } from '../providers';
1212
import { ConfigSection, ConfigSubSection } from '@grafana/experimental';
13-
import { ConnectionConfigProps, assumeRoleInstructionsStyle } from './ConnectionConfig';
13+
import { assumeRoleInstructionsStyle } from './ConnectionConfig.styles';
1414

1515
interface NewConnectionConfigProps extends ConnectionConfigProps {
1616
currentProvider?: SelectableValue<AwsAuthType> | undefined;

src/components/SIGV4ConnectionConfig.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
3-
import { ConnectionConfig, ConnectionConfigProps } from '../components/ConnectionConfig';
3+
import { ConnectionConfig } from '../components/ConnectionConfig';
44

5-
import { AwsAuthDataSourceSecureJsonData, AwsAuthDataSourceJsonData } from '../types';
5+
import { AwsAuthDataSourceSecureJsonData, AwsAuthDataSourceJsonData, ConnectionConfigProps } from '../types';
66

77
export interface SIGV4ConnectionConfigProps extends DataSourcePluginOptionsEditorProps<any, any> {
88
inExperimentalAuthComponent?: boolean;

src/components/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export { ConnectionConfig, type ConnectionConfigProps, DEFAULT_LABEL_WIDTH } from './ConnectionConfig';
2-
export { NewConnectionConfig } from './NewConnectionConfig';
1+
export { ConnectionConfig, DEFAULT_LABEL_WIDTH } from './ConnectionConfig';
32
export { Divider } from './Divider';

src/index.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
export { ConnectionConfig, type ConnectionConfigProps, DEFAULT_LABEL_WIDTH, Divider } from './components';
1+
export { ConnectionConfig, DEFAULT_LABEL_WIDTH, Divider } from './components';
22
export { SIGV4ConnectionConfig } from './components/SIGV4ConnectionConfig';
33
export { ConfigSelect, InlineInput } from './sql/ConfigEditor';
44
export { ResourceSelector, type ResourceSelectorProps } from './sql/ResourceSelector';
55
export { type SQLQuery } from './sql/types';
66
export { QueryEditorHeader, QueryCodeEditor, FormatSelect, FillValueSelect, FillValueOptions } from './sql/QueryEditor';
7-
export * from './sql/utils';
8-
export * from './types';
9-
export * from './regions';
10-
export * from './providers';
7+
export { filterSQLQuery, applySQLTemplateVariables, appendTemplateVariablesAsSuggestions } from './sql/utils';
8+
export {
9+
AwsAuthType,
10+
type AwsAuthDataSourceJsonData,
11+
type AwsAuthDataSourceSecureJsonData,
12+
type AwsAuthDataSourceSettings,
13+
type ConnectionConfigProps,
14+
} from './types';
15+
export { standardRegions } from './regions';
16+
export { awsAuthProviderOptions } from './providers';

src/types.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DataSourceJsonData, DataSourceSettings } from '@grafana/data';
1+
import type { DataSourceJsonData, DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
22

33
export enum AwsAuthType {
44
Keys = 'keys',
@@ -28,3 +28,19 @@ export interface AwsAuthDataSourceSecureJsonData {
2828
}
2929

3030
export type AwsAuthDataSourceSettings = DataSourceSettings<AwsAuthDataSourceJsonData, AwsAuthDataSourceSecureJsonData>;
31+
32+
export interface ConnectionConfigProps<
33+
J extends AwsAuthDataSourceJsonData = AwsAuthDataSourceJsonData,
34+
S = AwsAuthDataSourceSecureJsonData
35+
> extends DataSourcePluginOptionsEditorProps<J, S> {
36+
standardRegions?: string[];
37+
loadRegions?: () => Promise<string[]>;
38+
defaultEndpoint?: string;
39+
skipHeader?: boolean;
40+
skipEndpoint?: boolean;
41+
children?: React.ReactNode;
42+
labelWidth?: number;
43+
inExperimentalAuthComponent?: boolean;
44+
externalId?: string;
45+
newFormStylingEnabled?: boolean;
46+
}

0 commit comments

Comments
 (0)