Skip to content

Commit

Permalink
Fix ESM build path (#78)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jackw authored Mar 15, 2024
1 parent 0202814 commit 888e112
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 40 deletions.
4 changes: 3 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = {
...require('@grafana/toolkit/src/config/prettier.plugin.config.json'),
trailingComma: 'es5',
singleQuote: true,
printWidth: 120,
};
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## v0.3.3

- Fix: broken ESM imports due to `src` in ESM build output path
- Fix: circular dependencies in components
- Fix: ESM builds importing entire react, grafana/ui, grafana/data, and grafana/experimental
- Refactor: prefer named exports over asterisk in barrel files

## v0.3.2

Expand Down
3 changes: 2 additions & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default [
plugins: [
externals({
deps: true,
include: ['react', '@grafana/data', '@grafana/ui', '@grafana/runtime', 'lodash'],
include: ['react', '@emotion/css', '@grafana/data', '@grafana/ui', '@grafana/runtime', 'lodash'],
packagePath,
}),
resolve(),
Expand All @@ -30,6 +30,7 @@ export default [
sourcemap: true,
dir: path.dirname(pkg.module),
preserveModules: true,
preserveModulesRoot: './src',
},
],
},
Expand Down
5 changes: 5 additions & 0 deletions src/components/ConnectionConfig.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { css } from '@emotion/css';

export const assumeRoleInstructionsStyle = css({
maxWidth: '715px',
});
30 changes: 4 additions & 26 deletions src/components/ConnectionConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
import React, { FC, useEffect, useMemo, useState } from 'react';
import { Input, Select, InlineField, ButtonGroup, ToolbarButton, FieldSet, Collapse } from '@grafana/ui';
import {
DataSourcePluginOptionsEditorProps,
onUpdateDatasourceJsonDataOptionSelect,
onUpdateDatasourceResetOption,
onUpdateDatasourceJsonDataOption,
onUpdateDatasourceSecureJsonDataOption,
} from '@grafana/data';
import { config } from '@grafana/runtime';
import { standardRegions } from '../regions';
import { AwsAuthDataSourceJsonData, AwsAuthDataSourceSecureJsonData, AwsAuthType } from '../types';
import { AwsAuthType, ConnectionConfigProps } from '../types';
import { awsAuthProviderOptions } from '../providers';
import { css } from '@emotion/css';
import { NewConnectionConfig } from './NewConnectionConfig';
import { assumeRoleInstructionsStyle } from './ConnectionConfig.styles';

export const DEFAULT_LABEL_WIDTH = 28;
const DS_TYPES_THAT_SUPPORT_TEMP_CREDS = ['cloudwatch', 'grafana-athena-datasource'];
const toOption = (value: string) => ({ value, label: value });
const isAwsAuthType = (value: any): value is AwsAuthType => {
return typeof value === 'string' && awsAuthProviderOptions.some((opt) => opt.value === value);
};
export interface ConnectionConfigProps<
J extends AwsAuthDataSourceJsonData = AwsAuthDataSourceJsonData,
S = AwsAuthDataSourceSecureJsonData
> extends DataSourcePluginOptionsEditorProps<J, S> {
standardRegions?: string[];
loadRegions?: () => Promise<string[]>;
defaultEndpoint?: string;
skipHeader?: boolean;
skipEndpoint?: boolean;
children?: React.ReactNode;
labelWidth?: number;
inExperimentalAuthComponent?: boolean;
externalId?: string;
newFormStylingEnabled?: boolean;
}

export const ConnectionConfig: FC<ConnectionConfigProps> = (props: ConnectionConfigProps) => {
const [isARNInstructionsOpen, setIsARNInstructionsOpen] = useState(false);
Expand Down Expand Up @@ -184,9 +168,8 @@ export const ConnectionConfig: FC<ConnectionConfigProps> = (props: ConnectionCon
<ol>
<li>
<p>
1. Create a new IAM role in the AWS console,
and select <code>AWS account</code> as the Trusted entity,
and select <code>Another AWS account</code> as the account.
1. Create a new IAM role in the AWS console, and select <code>AWS account</code> as the Trusted
entity, and select <code>Another AWS account</code> as the account.
</p>
</li>
<li>
Expand Down Expand Up @@ -302,8 +285,3 @@ export const ConnectionConfig: FC<ConnectionConfigProps> = (props: ConnectionCon
</>
);
};

export const assumeRoleInstructionsStyle = css({
maxWidth: '715px',
})

4 changes: 2 additions & 2 deletions src/components/NewConnectionConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
onUpdateDatasourceSecureJsonDataOption,
SelectableValue,
} from '@grafana/data';
import { AwsAuthType } from '../types';
import { AwsAuthType, ConnectionConfigProps } from '../types';
import { awsAuthProviderOptions } from '../providers';
import { ConfigSection, ConfigSubSection } from '@grafana/experimental';
import { ConnectionConfigProps, assumeRoleInstructionsStyle } from './ConnectionConfig';
import { assumeRoleInstructionsStyle } from './ConnectionConfig.styles';

interface NewConnectionConfigProps extends ConnectionConfigProps {
currentProvider?: SelectableValue<AwsAuthType> | undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/components/SIGV4ConnectionConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
import { ConnectionConfig, ConnectionConfigProps } from '../components/ConnectionConfig';
import { ConnectionConfig } from '../components/ConnectionConfig';

import { AwsAuthDataSourceSecureJsonData, AwsAuthDataSourceJsonData } from '../types';
import { AwsAuthDataSourceSecureJsonData, AwsAuthDataSourceJsonData, ConnectionConfigProps } from '../types';

export interface SIGV4ConnectionConfigProps extends DataSourcePluginOptionsEditorProps<any, any> {
inExperimentalAuthComponent?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { ConnectionConfig, type ConnectionConfigProps, DEFAULT_LABEL_WIDTH } from './ConnectionConfig';
export { NewConnectionConfig } from './NewConnectionConfig';
export { ConnectionConfig, DEFAULT_LABEL_WIDTH } from './ConnectionConfig';
export { Divider } from './Divider';
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
export { ConnectionConfig, type ConnectionConfigProps, DEFAULT_LABEL_WIDTH, Divider } from './components';
export { ConnectionConfig, DEFAULT_LABEL_WIDTH, Divider } from './components';
export { SIGV4ConnectionConfig } from './components/SIGV4ConnectionConfig';
export { ConfigSelect, InlineInput } from './sql/ConfigEditor';
export { ResourceSelector, type ResourceSelectorProps } from './sql/ResourceSelector';
export { type SQLQuery } from './sql/types';
export { QueryEditorHeader, QueryCodeEditor, FormatSelect, FillValueSelect, FillValueOptions } from './sql/QueryEditor';
export * from './sql/utils';
export * from './types';
export * from './regions';
export * from './providers';
export { filterSQLQuery, applySQLTemplateVariables, appendTemplateVariablesAsSuggestions } from './sql/utils';
export {
AwsAuthType,
type AwsAuthDataSourceJsonData,
type AwsAuthDataSourceSecureJsonData,
type AwsAuthDataSourceSettings,
type ConnectionConfigProps,
} from './types';
export { standardRegions } from './regions';
export { awsAuthProviderOptions } from './providers';
18 changes: 17 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataSourceJsonData, DataSourceSettings } from '@grafana/data';
import type { DataSourceJsonData, DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';

export enum AwsAuthType {
Keys = 'keys',
Expand Down Expand Up @@ -28,3 +28,19 @@ export interface AwsAuthDataSourceSecureJsonData {
}

export type AwsAuthDataSourceSettings = DataSourceSettings<AwsAuthDataSourceJsonData, AwsAuthDataSourceSecureJsonData>;

export interface ConnectionConfigProps<
J extends AwsAuthDataSourceJsonData = AwsAuthDataSourceJsonData,
S = AwsAuthDataSourceSecureJsonData
> extends DataSourcePluginOptionsEditorProps<J, S> {
standardRegions?: string[];
loadRegions?: () => Promise<string[]>;
defaultEndpoint?: string;
skipHeader?: boolean;
skipEndpoint?: boolean;
children?: React.ReactNode;
labelWidth?: number;
inExperimentalAuthComponent?: boolean;
externalId?: string;
newFormStylingEnabled?: boolean;
}

0 comments on commit 888e112

Please sign in to comment.